mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-27 21:45:16 +01:00
* Enhance Windows build matrix with AVX2 variants * fix(lang): the two Polish lines of the download area written with \n, so they match the tooltip and the hint * fix(files): data named in another case is found on Linux, folders included The parser and the loaders lowercase every name they read, while the data made on Windows has files and folders named in any case (scenery/Braniewo, textures/siec_trakcyjna_ph/.../STS_*.tga, sounds/sip/Gorki.wav). FileCased matched the file name only, so a folder in another case wasn't found. - FileCased walks every part of the path on Linux, the folder listings kept by their lowercase and read again once the folder changed; Windows as it was - FileExists finds the file in any case on Linux, and the variant with names and extensions gives back the name as it's on the disk, so textures, materials, sounds, station announcements and scripts open that name - models, sound captions, timetables and nodebank previews open the file as it's named on the disk; the texture format is told by the extension in any case * fix(files): the banks keep the names asked for, only the opening takes the case of the disk The textures, materials and sounds are kept by the names they're asked for. Given back as named on the disk, a file in another case missed the bank and was loaded again on every request. - FileExists with names and extensions finds the file in any case but gives back the name asked for; FileOnDisk gives the file to open, used where textures, sounds and scripts are opened - FileExists of a single name is a plain check again, the places checking it and opening the same name stay as they were - the texture format is told by the extension asked for again - a folder changed shortly before it was read is read again for a name missing from it, the time of a change being as coarse as the clock of the file system; a listing cut short isn't kept * fix(files): a folder changed in the future isn't read again on every name missing from it * perf(files): a file missing costs a single check, as before Measured in a case sensitive folder (3000 textures, every 20th in mixed case, looked up the way Texture.cpp does), the walk over every part of the path made a texture lookup 4-5 times slower than master: each name tried and missing checked every folder of its path. - the folders found are kept by the name they're given with, the missing ones for a second, so a missing file checks its folder alone - a folder named as it is on the disk is taken without its listing - the time a folder was changed is looked at once a second at most The lookup is now as fast as master's (about 180 us per texture on NTFS in both) while finding the files named in another case too. * fix(files): terrain files named in another case are found on Linux The terrain directive names .txtf/.btf files in lowercase, as the parser gives every token. The name is now taken as it is on disk, from the text file first, so the binary file is made next to the text and the editor's references and layers keep one name. * fix(files): models named in another case are found on Linux The manager of the models looked for the file with FileExists of a single name, a plain check again since the banks keep the names asked for, so a model named in another case (models/przejazdy/plyty3_L, dynamic/pkp/st44_v2/main/2M62-0685-A) was reported missing before TModel3d::LoadFromFile() could open it as it's named on the disk. find_on_disk() finds the file in any case and gives back the name asked for, the key of the bank. * refactor(files): named functions instead of the lambdas of the folder cache (Sonar S2259, S3608, S6004) Sonar took the folder captured by the lambda reading it for a reference to null, failing the quality gate on reliability. The folder is read and the path kept by functions in the anonymous namespace, the age of the listing declared in its if. * fix: the simulator opens more than 512 files at once, and a shader it can't open says why With "physicslog yes" every driver keeps its .dat open, and a large scenery (Tomaszewo: some 500 vehicles, cars of the roads included) took all 512 streams the MSVC runtime gives: the next fopen failed and the simulator stopped at "cannot read shader: shaders/map.vert" on opening the map. The limit is raised to 8192 at the start (the soft limit of open files up to the hard one on Linux), and a shader file that doesn't open is told as such, with the system's reason, rather than as one that can't be read. * feat(blackbox): the black box on its own, writing the tapes of the user's vehicles at the end "blackbox yes" in eu07.ini records the black box with the physics logs on or off, "blackbox no" never; with no entry it goes with "physicslog yes" as before. With the physics logs off, the recorder keeps the line of the physics log of the driver the user is with, every 0.05 s, and writes it to physicslog/<vehicle>.dat when the recording closes: the speed recorder's tape of the vehicles the user was in, without every vehicle keeping a log open and written twenty times a second. The line and the header of the log are made by one function of the driver, which its own log writes too, and the file is opened the same way, so the two are the same to the byte: the readers of these logs (the old Hasler tape viewer, the starter) read them as before. * feat(physicslog): the logs written every two seconds by a thread of their own, no file kept open; the black box's tapes as it goes "physicslog yes" kept the .dat of every vehicle with a driver open for the whole run and flushed it twenty times a second from the simulation's thread: some 580 open files on Tomaszewo. The lines are kept now and a thread of their own writes them every two seconds, each file opened only for the moment it is written to. The files, their lines and their text mode stay as they were. - The black box, with the physics logs off, writes the tapes of the user's vehicles through the same writer as it goes, not at the end. A log begins when the user is first in the vehicle and goes on while the user looks around outside, until another vehicle is taken; back in it, the log goes on after the gap. The vehicle's own driver keeps the log only if it is the primary one, as a passive one's clock stands still; otherwise the driver of its train does. - What is kept is written when the simulator closes, after the black box, at the end of a test run, and when the test watchdog ends a run. A crash loses the last two seconds. - On Tomaszewo with the black box alone, the one tape grows every two seconds. With "physicslog yes", the 581 logs grow and the simulator holds as many handles as without them; writing them takes the thread about 1.9 s, which the closing waits for once. * feat(blackbox): the cab record holds the speed of the wheels, apart from the vehicle's when they slip The speed of the cab record is the vehicle's. The speedometer, and a speed recorder's tape with it, shows the speed of the wheels as they turn, which runs away from it while they slip and drops to 0 while they are locked in a skid. It is added at the end of the record (194 bytes), where the readers skip what they don't know; the .dat tapes have it already, in their second column. * fix(ci): build OpenAL Soft with the PipeWire, PulseAudio and ALSA backends, so the Linux game has sound The Linux job builds OpenAL Soft 1.24.2 from source, but the runner had none of the headers of its audio backends, and OpenAL Soft's CMake leaves out every backend it can't find. The bundled libopenal.so.1 had only OSS, Null, Wave and Loopback. Modern distributions and the Steam Linux Runtime have no /dev/dsp, so the game logged "Failed to obtain audio device" and played nothing, with any Steam Linux Runtime and without one. - install libasound2-dev, libpulse-dev and libpipewire-0.3-dev before building OpenAL Soft - configure it with ALSOFT_REQUIRE_PIPEWIRE/PULSEAUDIO/ALSA, so a missing header fails the build instead of shipping a library without sound The backends are loaded with dlopen at run time (ALSOFT_DLOPEN is on by default), so the bundled library gains no new dependency. Tested by putting an OpenAL Soft 1.24.2 with these backends next to the game from the Steam depot: under Steam Linux Runtime 4.0 the sound works. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(editor): the certificates of https looked for where the distribution keeps them The Linux game bundles the libcurl of Ubuntu, which knows only Ubuntu's /etc/ssl/certs/ca-certificates.crt. Fedora, RHEL and openSUSE keep the certificates elsewhere, so every download of the editor (orthophoto, terrain model, topo map) failed there with a certificate error. The file is taken from SSL_CERT_FILE or CURL_CA_BUNDLE when set, else the first of the files the distributions keep, and passed as CURLOPT_CAINFO. With none found libcurl keeps its own. * fix(editor): an https proxy checked with the same certificates CURLOPT_PROXY_CAINFO gets the file found for CURLOPT_CAINFO, so a download through an https:// proxy on Fedora or RHEL doesn't fail on the proxy's certificate. * fix(ci): the no-AVX2 Windows build has its own concurrency group and its own public download After master was merged the two Windows variants shared one concurrency group with cancel-in-progress, so one cancelled the other, and the publish job looked for an artifact name the matrix no longer produces. Each variant now has its own group, the publish job downloads both, and the release carries maszyna-windows-x64.zip (AVX2, the old name, so the links already handed out still work) and maszyna-windows-x64-noavx2.zip. The AVX2 variant passes -DENABLE_AVX2=ON explicitly instead of an empty flag. * build: a build without AVX2 has _noavx2 at the end of its executable name With ENABLE_AVX2=OFF the executable is eu07-x64_<date>_<hash>_noavx2.exe (eu07-x64_noavx2.exe without ADD_VERSION_SUFFIX), so a starter can tell the two builds apart by the name alone and pick this one on a CPU without AVX2. The AVX2 build keeps its name. * ci: Linux is built without AVX2 too, published as maszyna-linux-x64-noavx2.tar.gz The Linux job becomes the same two-variant matrix as Windows (ENABLE_AVX2=ON/OFF), each variant with a concurrency group of its own. The publish job downloads both Linux artifacts, restores the executable bits in both and releases maszyna-linux-x64.tar.gz (AVX2, the old name) next to maszyna-linux-x64-noavx2.tar.gz. The no-AVX2 executable is eu07_<date>_<hash>_noavx2. * fix(renderer): the legacy renderer clears the arrays the scene left before it draws the ui The legacy renderer drew the ui with the client arrays of the last scene draw still enabled: the texture coordinates of the normal map unit and the normals, pointing into the vertex buffer of whatever was drawn last, 48 bytes a vertex. The ImGui backend sets up the vertex, colour and texture coordinates of the active unit only, so the driver read the stale arrays with the indices of the ui. Once the ui had more vertices than that buffer, the NVIDIA driver read past its end and the game crashed; a crash dump of the editor (an area selected, a track being laid) shows the read of vertex 15113 at a 48-byte stride in ImGui_ImplOpenGL2_RenderDrawData. The arrays are now disabled on every texture unit the geometry uses, with the normal and colour arrays, inside the glPushClientAttrib already there, so the scene gets its state back after the ui. The default and the experimental renderers don't go through this code. * fix(app): a renderer this build doesn't have starts the full one, not the legacy one The starter writes "gfxrenderer vulkan" for the Vulkan renderer of the builds that have it. This exe doesn't know the word, and every word other than default/experimental fell to the legacy renderer: a player who picked Vulkan got the slowest renderer, the one whose ui crashes on NVIDIA (the arrays left by the scene). "experimental" in a build without the NVRHI renderer ended with "no renderer found!" and no game at all. After the settings are read, a gfxrenderer word this build has no renderer for becomes "default", with a line in the log saying so. The words it knows stay as they were: full/default, legacy, simple, null, the older starters' simpleshader and off (legacy as before), and experimental where it is built. * fix(settings): the gfxrenderer word read in any case, as the starter reads it A hand-written "gfxrenderer Legacy" started the legacy renderer only because every unknown word did; with unknown words going to the full renderer it would have changed. The word is lowercased when read, as StarterNG's RenderEngineOf does, so Legacy, Simple or Full mean what they say. * fix(physicslog): a log whose file can't be written keeps its lines and header, and the writer is stopped once on every way out A failed write put its lines back, ahead of those since, so a file held by another program for a while gets its header and every line once it can be written; up to 4 MB kept per log. Stopping is joined once, and not from the writer's own thread. main stops the logs after an error it caught too, and the test watchdog flushes with a time limit, so a disk that doesn't answer doesn't keep the run from ending. * fix(blackbox): the wheels of the powered vehicle, as the speedometer has them, and the logs described as the drivers' they are In a unit driven from an unpowered car, the speed of the wheels was of the car the user is in, whose wheels never slip; now of the motor car, signed as the occupied vehicle's speed. The doc tells of a log per driver, and of the two seconds of real time a crash loses. * fix(physicslog): failed logs kept within 64 MB in all, cut outside the lock, never written twice; the writer knows itself when stopped The lines kept while files can't be written are cut to their share of 64 MB before the lock the simulation waits on. A log written in part is cut back to its length, so the next try doesn't write its start twice. A stop from the writer itself is told by its id even after another thread took it to join, and the watchdog's flush waits at most its time, the writing on a thread of its own. * feat(physicslog): the logs of the trains only, physicslog.trains "physicslog.trains yes" in eu07.ini writes the .dat log of each driver who drives rail vehicles, not of the passengers nor of the road vehicles that make "physicslog yes" hundreds of files on a big scenery: the tape of every train. A driver made primary later begins its log then, and isn't counted while it doesn't log. The black box goes with it when the ini says nothing of its own, and doesn't write a second log of a driver writing its own. The doc tells the doors' sides are the vehicle's, the driver's swapped in the rear cab. * fix(physicslog): a train's log begun at its first line, so passive crews get no file Every crew is primary in the constructor and the drivers but one of a train with crews in more vehicles are made passive only before it starts, so a log begun there left files with only the header. With physicslog on all logs begin at once as before; one of a train waits for update_logs. * fix(editor): the texture pickers let go of the images scrolled past, the memory no longer runs out The picker of the textures of a track offers every texture of the textures folder, and each tile that came into sight read its texture full size, into the graphics card and the memory, and kept it there for good. Scrolling through the list for a trackbed texture took about 2.5 MB a tile: some 900 tiles made 3.5 GB, the whole folder 28 GB, and the game went down once the memory ran out. An image out of sight for 3 seconds is now taken out of both again (texture_manager::unload, Unload_Texture of the renderers) and read anew when it's shown once more, a few a frame as before. Only a texture the scene has never drawn is let go; those of the scene stay to the resource sweep. The texture browser lets go of its images on Refresh too. The picker no longer lists textures/previews: the 4100 previews of the node bank are images of models, not textures of anything. Checked on td.scn by a scripted run: 8000 images of the picker read one batch a few frames after another held the game at 2-3 GB, where it went to 28 GB and fell before; images shown again after they were let go come back; a trackbed texture picked from the folder is drawn on the track after its image was let go. * fix(physicslog): the writer's destructor throws nothing, its wait a plain condition variable woken to stop; a driver of no vehicle controls nothing * fix(editor): the images of the materials let go of with all their textures, the browser's Refresh a frame later An image of a material read the material with all its textures, the normal and specular maps and the variants, and only the first one was let go of: those stayed in the memory for every material scrolled past. They are let go of together now (Unload_Material). texture_manager::unload also takes the textures read and not made yet, waiting for a worker still reading one, and deletes the gl texture itself: release() would read it back from the card with gfx.resource.move only for it to be dropped. The Refresh of the texture browser let go of the images in the middle of the frame, while panels drawn before it could still refer to them; it now marks them, and they go at the start of the next frame. Checked on td.scn by a scripted run: 8040 images of the picker read a batch every few frames end at 2.0 GB, against 2.3-2.6 GB before this and 1.1 GB at the start; a trackbed material picked from the folder is drawn on the track after its image was let go. * fix(physicslog): every stop asked wakes the writer, the one from itself too; no psyche for a driver of no vehicle * fix(editor): the image of a material with no texture in its first slot is let go of too Its normal and specular maps were read with it and stayed in the memory: the trim passed over every image with no texture of its own, the material along with it. * fix(physicslog): nothing that goes wrong in the writing ends the simulator; a name in 1250 makes a path on a Windows set to UTF-8 The writer's thread called flush() with nothing around it, so an exception leaving write() ended the process with std::terminate, with no message. One that happens: the file of a log was made a std::filesystem::path of the vehicle's name, which MSVC converts in the code page of the system and throws for bytes not of it; on a Windows with "Use Unicode UTF-8 for worldwide language support" a vehicle named in 1250, as the sceneries have them (0xB3 for ł), isn't UTF-8. - the file of a log is made of the name with MultiByteToWideChar without MB_ERR_INVALID_CHARS: the same file as before for every name of the code page, U+FFFD for the bytes not of it instead of a throw. Elsewhere the bytes are the name of the file as they were - a log whose writing throws for any other reason (memory) is kept for the next try as one whose file can't be written, and the other logs are written still - the thread, flush_for() and stop() write through flush_safely(), which lets nothing out: what was taken for a writing failing as a whole is lost and told in the log, the next writing goes on - the messages name the file by the bytes of the name, not by path::string(), which converts back Tests: a log which can't be written doesn't keep the others from theirs; a vehicle named in 1250 has its log, read back by physicslog_writer::file(). Reported in the review of #385. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(blackbox): the tapes go on after the editor, with the physics logs off The tapes of the user's vehicles were written by update() after the check for the writer of the recording, which close() drops on entering the editor (F11). With "physicslog no", the speed recorder's tape ended at F11 while the drivers' own logs of "physicslog yes" went on. The tapes are files of their own: they are kept from the moment the recording was to be made, the file made or not, closed or not, until the simulator closes, after the gap of the time in the editor. Only the recording itself stops at F11, as before. Reported in the review of #385. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(physicslog): what no file name may have on Windows is replaced in the name of a log, on every system A spawned vehicle is named <spawn>:<number>, and its log went to physicslog/<spawn>:<number>.dat. On NTFS that isn't even an error: it is the stream <number>.dat of the file <spawn>, which nothing lists, so the log was written and no one could find it. On Linux the file was there, under a name Windows can't open. The name of the file of a log has < > : " / \ | ? * and the control characters replaced by _, on every system, so the logs are named alike everywhere (spawn_ezt:12 is spawn_ezt_12.dat), and a _ before a name Windows keeps for a device (con, nul, com1..., with an extension too). The bytes of 1250 stay. The black box tells the log it begins by the same name. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * refactor(renderer): a material's textures let go of in one place, for every backend Unload_Material walked the textures of a material and of its variants the same way in both opengl renderers, and Sonar counted its declarations, set into the long run of overrides the two headers share, as duplicated: 5.2% of the new code, 3% allowed. The walk is gfx_renderer's now, over IMaterial::GetAllTextures and the backend's Unload_Texture. Materials that don't tell their textures, the Vulkan renderer's, give none, and are left alone as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * AI: shunting brakes for a stop point again; test mode: no false SPAD for a train set across a signal (#409) * fix(ai): shunting AI brakes for a stop point again, the braking curve doesn't plan from a brake table left at zero The braking curve outside the final approach plans from the consist brake table sincece87aa0e(#187, merged with #264) whenever the brake is pneumatic. That table is worked out only for train running (Obey_train, Bank); in shunting it stays at zero, the planned full braking falls to its floor of 0.01 m/s2, and the demand comes out at a few hundredths of a m/s2, above the shunting brake threshold of -0.2. A shunting engine then rolled on without braking until the final approach, too late, and ran through the signal it was to stop at (seed 480873929 of l053_poranek: ep07p-2003 at sandomierz_g4_sem_info, sm42-1096, et22-654). With no worked out table the curve is again the constant deceleration over the distance left, as it was beforece87aa0eand as #187 meant to keep it for shunting. Train running is unchanged. The curve moves out of TController into vehicle/brakingcurve.{h,cpp} so that it is unit tested: tests/unit/test_braking_curve.cpp checks a shunting engine braking to a stop point with the zeroed table, and that a train with a worked out table gets the same demand as before. * test(ai): pin the train braking-curve demand to the results of the code before the move A brake table that grips harder as the train slows and a gradient, so that a wrong gravity sign, table index or a dropped term in the shaped demand shows; the expected values were worked out with the code removed from TController::adjust_desired_speed_for_braking_curve. * fix(test): a train set across a signal doesn't pass it at danger the moment the AI first looks at it The speed table takes in events up to a train length behind the head, so a signal the train stands across at the start of a scenario is found already behind the head, becomes elapsed on its first update, and the test mode reported it as passed at danger (calkowo_lotos: st43-189 at mac_daleko3_sem_info, manewrowo3: st43-100 at suw_szopa_a02_sem_info, both at 13.6 s with the train at a stand, the signal 20 m behind the head). A point now counts as passed only when the head of the train had it ahead once; the blackbox record of passed signals follows the same rule. * fix(test): a signal found up to 5 m behind the head still counts as seen ahead The distance to an event is found in steps of a metre from the position of its memory cell, so a signal just ahead of the head (a train stopped short of it when the autopilot takes over, or set right at it at the start) could come out slightly behind it, and passing it would not be reported. The trains set across a signal that the previous commit is about stood 20 m past it. Still not reported: a signal crossed while the speed table is being traced anew in motion (a Timetable: command to a running train, the autopilot taking over in motion), as it is found behind the head when the trace is made. * docs(test): say what the seen-ahead tolerance gives up A train set less than 5 m past a signal at stop is still reported to pass it at danger: standing that close it can't be told from a train stopped just short of the signal, which the tolerance is there for. --------- Co-authored-by: maj00r <maj00r@host> * fix(camera): the roll of the cab shake tilts the view about the line of sight again (#414)623c4f82(#97, in 26.05.1) changed the order of the camera rotations from Z, X, Y to X, Y, Z. The order matters only with a roll, which the cab shake gives (Angle.z, set in drivermode.cpp), or a camera entry of the scenery with a roll. Applied last, in the space of the cab, the roll nodded the view up and down when looking out of a side window instead of tilting it. The roll is multiplied in first again, as in 26.05. Co-authored-by: maj00r <maj00r@host> * fix(particles): the smoke of a cold diesel keeps the colour of its template (#413)bcb9e644(#109) turned a comparison into an assignment: the smoke of a vehicle in air at 5 degrees or less, or with its engine under 45 degrees, got the colour 128,128,128. The emitter colour is on a 0-1 scale, so the smoke turned pure white, glowing at night, and stayed so once the engine warmed up. Up to 26.05 the line compared and did nothing; the smoke keeps the colour of its template again, as it did then. Co-authored-by: maj00r <maj00r@host> * Fix stutter with fpslimit on Windows and a texture unit cache race with threaded Python screens (#399) * fix(render): the python upload thread only marks the texture unit cache stale, the drawing thread clears it update_from_memory() runs on the python upload thread with python.threadedupload (the default), and sincee230d7b9it cleared opengl_texture::units there outright. That raced Bind_Material filling the same array for its multi-bind: a unit reset between the fill and glBindTextures() made the bind of that unit fail, and the object was drawn with the texture of the one drawn before it, for a frame, at the rate of the screens. The thread now sets an atomic flag, and the drawing thread clears the cache when it next binds textures (bind() and the multi-bind of Bind_Material), so a screen texture given a new gl name is still rebound. * fix(app): fpslimit asks Windows for the 1 ms timer, the frames no longer come in turns long and short The wait of fpslimit sleeps, and Windows wakes a process which didn't ask for a finer timer in steps of up to ~15.6 ms. A 10 ms slot of fpslimit 100 ended ~15.6 ms later, the pacer made it up with no wait in the next frame, and with vsync on the frames were shown for one or two refreshes in turn: visible stutter at a steady FPS. timeBeginPeriod(1) is held from the settings to the exit, only when fpslimit is set. * fix: the 1 ms timer also for an fpslimit set by the scenery, the stale unit cache checked with a plain load first A config block of the scenery is parsed after the settings and can set fpslimit, so the timer period is asked for at the first wait of the pacer too, once. bind() checks the stale flag of the unit cache with a relaxed load before the exchange, which it does for every texture. * fix(textures): the stale flag of the unit cache uses the default memory order (Sonar S8417) On x86 a sequentially consistent load and exchange cost the same as the relaxed and acq_rel ones; only the store in invalidate_unit_cache() becomes an xchg, and it runs rarely. --------- Co-authored-by: maj00r <maj00r@host> * fix(camera): the cab shake taken at the frame's moment between its fixed steps, it no longer moves in steps (#403) The shake of the cab camera (ShakeState) is stepped by update_shake at a fixed 1/50 s, while the camera read the raw state every frame. At any frame rate other than 50 the shake moved in steps: some frames showed the same state as the one before, others jumped one or two steps at once. Players with 144/165 Hz screens saw the cab jump around the camera. The vehicle now keeps the state from before the last step (ShakeStateBefore), and the camera takes the state between the two at the share of the step the simulation time has reached (shake_between). The offset and the velocity are blended, the angles worked out from the blended velocity. The shake itself is computed as before, with the same fixed step and the same springs; only what the camera shows of it changes. It lags the vehicle by a constant 1/50 s instead of 0 to 1/50 s. Measured with the same build and the blending switched off by a temporary environment variable (not in this commit), the EU07 on td.scn driven by the AI, frames over 30 km/h, two runs of each: - 60 fps: frames with the shake standing still 25% -> 0%, the change in its speed frame to frame 4-5 times smaller for the offset, a third smaller for the angles - ~144 fps: 65% -> 0%, 10-18 times smaller for the offset, 4 times for the angles - no fps limit (~520 fps): 90% -> 0% Co-authored-by: maj00r <maj00r@host> * fix: inverted clamp bounds give the upper bound again, as the old clamp did (#412) * fix: inverted clamp bounds give the upper bound again, as the old clamp did The project's own clamp() of 26.05 applied the lower bound first and the upper one last, so bounds given the wrong way round always gave the upper one. Its calls became std::clamp (undefined for such bounds) and, where the bounds can cross, safe_clamp, which swapped them instead. Neither gives the old result. - safe_clamp is the old clamp again, min(max(value, lo), hi). This restores 26.05 at every place it is used, among them the AI's dynamic brake test (its demand was fAccThreshold x1.21, the swap made it x1.01), the generator voltage, the heavy cargo acceleration of the AI and the EP correction of the brake. - The cab camera is kept inside the cab with safe_clamp. The bounds come from the .mmd as written and some cabs have them reversed (the B cars of SA134 and 21xM, ET40, 754); with std::clamp the camera jumped between the two bounds every frame on MSVC, as its result is fed back. * fix: every call of the old clamp gives what it gave up to 26.05.1d1f16411(#99) made every call of the project's clamp() std::clamp. Where the bounds come from the data or are computed at runtime they can cross, and then std::clamp gives another result (undefined behaviour; MSVC gives the lower bound unless the value is above the upper one) where the old clamp gave the upper bound. These calls use safe_clamp, the old clamp, too: - Mover: the pantograph pressure (MaxPress), the compressor switch (CompressorListPosNo), the coupler distance (DmaxB, DmaxC), the engine revolutions, the eimic ramp (CtrlDelay), the eimic limit (eimic_max), the speed control ramp (PowerUpSpeed, PowerDownSpeed), the load (MaxLoad), the magnet of the security system (Dim.L); - DynObj: the coupler distance of the buffers (DmaxB), the axle distance (Dim.L); - Train: the brake handle positions (BrakeCtrlPosNo, the range of the handle); - the legacy renderer: the mouse pick (the window size). With the bounds in order nothing changes. Calls whose bounds the code keeps in order (constants, SplineFidelity 1-4, the season table, the guarded output calibration) give the same result with std::clamp and stay as they are. The load offset takes its arguments in the 26.05.1 order again;fa2ed089swapped them, which with the old clamp differs only for a negative load. The bump at a rail joint gives the old result again. Up to 26.05.1 its clamps had 0 in place of the value (since96f43e11and4d72d352), and the old clamp made that the headroom Vmax - (Vel + 0.32 Vmax), negative above 68% of the top speed, capped from above only;d464628aand03bfbb13kept it at 0 or above. Only damaged track has the bump: a damage flag in the .scn, a derailer set by an event, a track made on a derailment. The interior light of the cab in the 3.3 renderer is computed in double again, as befored1f16411. The call added since (stepped_uc_value,00955513) keeps what master does: bounds given the other way round are put in order. * fix: the alpha of a particle in the legacy renderer as up to 26.05.1, the NaN cases of the clamp tested Up to 26.05.1 the alpha was clamp<std::uint8_t>( particle.opacity * 255, 0, 255 ): the float was made a byte first, so the clamp did nothing and an opacity over 1 (a smoke max_opacity over 1) wrapped round, 1.2 giving 50. The move to std::clamp made it 255. It's made a byte as then again, through int: the byte the x86-64 compilers gave, without the undefined behaviour of that conversion (MSVC makes the same two instructions of both). openglparticles.cpp goes with feat/gl46-migration; its opengl33 counterpart, std::clamp( opacity, 0, 1 ), already gives what 26.05.1 gave. The tests pin what the old clamp gave with NaN: a NaN value stays NaN, a NaN bound doesn't clamp. The checks named after the AI braking test and the bump at a rail joint say they test the helper with the arguments of those calls, not the calls. * test: the includes of the clamp tests before the project's headers <cmath> and <limits> go up, after the test headers, so the change no longer touches the lines #416 adds its includes after. With both merged <cmath> is included twice, which is harmless. --------- Co-authored-by: maj00r <maj00r@host> * Python screens: the worker's image goes in place only after its fence, not a bare glFlush (#411) * fix(python): a screen uploaded by the worker goes into a texture of its own, put in place after a fence With python.threadedupload (the default) the worker wrote the image into the texture the drawing thread draws from, with glTexImage2D and glGenerateMipmap from its own context, and only a glFlush after. Nothing ordered the two contexts: the drawing one could sample the texture while its storage was being made anew, its level 0 half written or its mipmaps not made yet, and on a change of size the worker deleted the texture and wrote a new name into `id` with no synchronisation. The worker now uploads each image into a new texture, sets a fence after it and flushes. The drawing thread, once per frame in python_taskqueue::update(), waits for that fence on the gpu (glWaitSync, the cpu goes on), deletes the old texture and puts the new one in place. The worker no longer touches the texture drawn from, nor `id`. An image the drawing thread didn't take yet is dropped by the next one. Without sync objects the worker waits for the upload with glFinish. The windows of python.displaywindows with python.sharectx bound the texture once; they now bind the name of the last image put in place, which python_rt keeps for them. Uploads on the drawing thread (python.threadedupload no, the Lua and WebAssembly screens, the editor) are as they were. * fix(python): the image of the worker goes in place once its fence is signalled, the viewer binds it each frame From the review of8811ee5a: - glWaitSync ordered only the context of the main window. The extra viewports and the windows of python.displaywindows draw in contexts of their own and could bind the new texture before the upload was done. commit_thread_upload() now asks the fence without waiting (glClientWaitSync, timeout 0) and puts the image in place only once it is signalled, so every context binding it afterwards has it whole. Until then the task stays in the upload queue and is asked again the next frame. - The drawing thread chose between upload and commit by python.threadedupload, the worker by whether it got a context. With python.threadedupload on and no context made for the worker, the screens were no longer updated. The task now records that a worker uploaded it. - The viewer of python.displaywindows told a new image by its texture name, but a deleted name comes back for a later texture. It binds the name of the last image each frame, read under the lock of the render target, and the name it starts with is read on the drawing thread when it is made. * fix(python): the old texture deleted under the lock the viewers bind under, a fence not made waited for with glFinish From the review of #411: - finish_upload() deleted the old texture before it took the lock of the render target, and the windows of python.displaywindows read the name under that lock but bound it after letting go of it. A window could bind a name already deleted, or already given to the next upload. In a compatibility context (the legacy renderer) that makes a new empty texture: a black frame and a texture never deleted. The commit and the publishing of the new name now go under the lock, and the viewer binds under it too. A name bound before the deletion stays alive in that window's context while bound. - A glFenceSync that returns no fence was taken for a signalled one: the image went in place at once, with nothing ordering the contexts. The worker now waits for its upload with glFinish then, as without sync objects. * fix(python): the worker waits for the lock of the screen without the gil, no flush after a finish From the review of939514ea: - The drawing thread now holds the lock of the render target for a whole upload with python.threadedupload off. The worker, copying the next image under that lock, waited for it holding the gil. It now lets the gil go around the lock and the copy: the bytes it copies stay valid, the object is immutable and held by the reference the worker has. - glFlush after glFinish did nothing; the worker flushes only when it made a fence. --------- Co-authored-by: maj00r <maj00r@host> * fix(models): a scenery light that is off no longer shows lit for a moment the first time it comes into view (#407) * fix(models): a scenery light that is off no longer shows lit for a moment the first time it comes into view Sinced13c27a7(the light blinking rework) the opacity of a light changes step by step from its last value, and the opacities start at 1. RaAnimate runs only for the instances that are drawn, so a model with "lights 0" (a W24 LED indicator, for one) was drawn lit when it first came into range and faded out over 0.45 s. Befored13c27a7the opacity of a plain on/off light was worked out anew from a timer starting at 0, so a light that is off was off from the first frame. Now the first time an instance is animated its lights take their current state at once, whether it came from the definition or from an event since. Every later change fades as before. The light threshold modes (ls_Dark, ls_Home) are untouched. The only other difference from befored13c27a7: a light that is on no longer fades in the first time it is drawn. * fix(models): the light opacity step written without an implicit double to float conversion (Sonar S5276) The sum is still worked out in double and rounded to float once, as the compound assignment did, so the result is the same to the bit. --------- Co-authored-by: maj00r <maj00r@host> * Editor: switch drives with no switch listed and marked; a deleted switch takes its drives and ballast along (#330) * feat(track): the rail code split by concern, the blades of the switches with the key frogs shaped from their templates The rails are laid by code of their own instead of inside Track.cpp: gauge lines (GaugeLine), knot lines (Knots.h), crossings and check rails (RailCrossings), rail materials (RailMaterials), measuring the rail profile (RailProfile), planning the cuts (RailPlan), the carving scan (RailCarve) and laying the geometry (RailLayer). A switch with the key frogs draws its blades from the tip where their planed nose ends to the heel, bent as they're thrown, and the rail behind them from the heel on, where they were laid from the start of the switch before; on a switch of the catalogue they start at the cut tip of the tables, 1.248 m from the joint at R 190, 1.5 m at R 300 (track_features::blades). The frogs cut from the rails, the wing and the check rails are built but switched off (track_features::crossings), the rails laid whole as before. The switches without the key keep the blades they had. A switch path can be a chain of pieces: pieces1 and pieces2 keep the parts of each path after the classic bezier, which stays as the approximation older versions read. A path with its radius given is a curve however gently it bends, a plain track a straight only where both of its control vectors lie along it. A vehicle trailing through a switch with a movable nose set the other way runs off the rails at it (TRAILED_SWITCH). * feat(render): the shared treads of the rails and their cut faces drawn, the cut faces in the matte variants of the rail materials Both renderers draw the treads a track shares with the rails it crosses, in the pick pass too, and a pass of their own for the faces where the rails are cut, the ends of the blades among them, in the matte variants of the rail materials, so the cut faces don't shine like the head the wheels polish. * feat(vehicle): an axle on a switch keeps to the path it came on, and coming from the frog end trails the switch through where the wheels reach the blades The switch thrown under an axle no longer moves it over onto the other path; it runs on along the one it entered. Coming from the frog end, where the blades are shaped or the frog has a movable nose, the switch set the other way is trailed through (rozprucie) only where the wheels get to the blades or to the nose, not as the axle enters the track; the other switches are trailed through as it enters, as before. * fix(track): the tracks drawn straight before, which their second control vector bends now, written to the log The simulator told a straight by the first control vector of a path alone, so a track whose second control vector bent it was drawn straight; now it's a curve. Such a track is named in the log as it loads, so a scenery made counting on the straight can be found: 25 tracks of lk357. Paths with both control vectors along them bend a centimetre or so at most and aren't named. * feat(track): 3D sleepers and switch timbers laid where the simulator makes the ballast, switched off in the build The sleepers of a track running alone are laid square to it, the timbers of the switches and crossings across the tracks running over them, shared by them, of the models set with sleepers3d and sleepers3dplain in eu07.ini; sleepers3dbed tells whether the ballast is laid under them too, lowered so they stick out of it. The layout of a cluster of tracks is worked out once and kept till a track of it changes, in a thread of its own while the simulation runs. timbermodel of a track, read and written back before, takes the place of the model of sleepers3d there. All of it is off whatever eu07.ini sets (track_features::sleepers), the tracks keeping their ballast and their sleeper models. * feat(render): the 3D sleepers and switch timbers drawn in instanced batches Render_Timbers lays the beams of the tracks in range where they're out of date and draws those of a run of tracks of a cell gathered by the model and its part or its level of detail, in as few instanced batches as they fit in; in the shadow pass only those near the camera. A track with them leaves its old sleeper model out. OpenGL 3.3 renderer only. * fix(track): the counts of what's wrong with the sleepers kept safe from the thread laying them, and that thread stopped before what it works with goes The counts of the beams clipped, dropped and off the plane, of the slowest and the biggest cluster, are counted by the thread working out the layouts in the background as well as by the simulation laying a cluster itself, and were plain values written by both; they're atomic now. What the thread keeps the clusters in, their version and the counts were made after the worker, as it first asked for them, and so destroyed before it at the exit while its thread could still be laying a cluster; they're made first now, the worker stopping and joining its thread before they go. The tracks go with the paths of the simulation, made before the worker. * revert(track): a tributary and a track of an unknown type load as before They came in with the rail code from the guards of the editor against crashing, and don't belong with the blades: a track of an unknown type loaded as a normal track of the railway could be joined to it and run on, and a tributary loaded as a river with its first path lost the second one when the editor saved the scenery. Both load as on master again; the place where the editor crashed on them is to be guarded where it is. * fix(track): the tracks drawn straight before named in the log once, as they load, and the paths of the switches with no radius told a straight as before in one term The log of the tracks the second control vector bends now was written each time the segments of a track were made again, as a track with its unevenness loads and as the editor changes or drags a track; it's written only the first time, as the track loads. The paths of a switch or a crossing with no radius keep the rule of master, a straight told by the first control vector alone, its two terms being the same length; they're one term now, with the comment saying so. * fix(track): the thread laying the sleepers stopped as the application exits, and loading no models itself The thread reads the scenery, which the application deletes as it exits well before the statics go: it's stopped and joined first thing in exit() now, the worker destroyed with the statics only where the application exits some other way, and not started again after. The models the beams are made of were loaded by the thread where it didn't find them, through the renderer, out of the thread of the renderer, into a map read by the simulation meanwhile: they're found under a lock now and loaded only by the threads other than it, again for all the tracks whenever a track changed since, before a layout is asked of it. With the 3D sleepers off in the build their settings aren't exported, and a track changed doesn't look for the tracks around to lay their beams again. * feat(track): the 3D sleepers turned on with sleepers3d in eu07.ini, no longer switched off in the build track_features::sleepers is gone: sleepers3d <model> in eu07.ini lays them, none (the default) lays nothing and the tracks keep their ballast, as before. The sleepers3d settings are written back with the others. The editor changes the tracks, so while it's open their sleepers are worked out on the main thread as they're needed, not in the background. * fix(render): only the part of a timber model drawn, not what else the model holds A timber model of parts may hold more than its begin, main and end, as the kits with the fastenings of the rails do. Those were drawn with each part of each timber, in the middle of the track; they aren't laid, so they're skipped now. * fix(track): the 3D sleepers laid only for a renderer which draws them Only the OpenGL 3.3 renderer draws the beams. With another one a track set to them lost its ballast to them, lowered or not laid at all with sleepers3dbed no, and nothing was drawn in its place. Draws_Timbers() of the renderer tells now, and where it's false the tracks keep their ballast, as with sleepers3d none. * fix(render): the submodels of a timber model left as they were after its parts are drawn They were all made visible after a part was drawn, the ones the model hides itself too, like Light_On, while the same model may stand in the scenery. The submodels of the top level besides the parts are listed as the model is loaded, hidden while a part is drawn and given back their own visibility after. The parts have to be at the top level of the model for that; a model with them deeper is logged and drawn whole. Render_Timbers no longer looks the model up under the lock for every run of tracks, the name set is enough there. * fix(render): a vertex whose faces give its texture no direction gets a tangent across its normal, not a NaN one The cut ends of the rails have one spot of the texture on all their corners, so their tangent came out of normalize() as NaN. The normal-mapped shaders then shaded them with a NaN normal: about half of the vertices of the cuts and frogs, and the end faces of the rails. * feat(track): the frogs cut from the rails turned on with frogs in eu07.ini, no longer switched off in the build frogs yes cuts the rails of the plain tracks and of the switches with the key frogs where they cross other rails, into frogs, wing rails and check rails. It's off by default: the rails are laid whole as before, the blades of the switches with the key are shaped still. * refactor(editor): the track mode file split into the files of its tools, the code as it was A pure move, so that the commits after it show what changes in each tool rather than a 4800-line file rewritten. The member functions of editor_mode go to the file the editor of this branch has them in: route, straights, lay, switchplace, switchdrive, switchtool, trackgizmo, and the rest stays in editormodetrack.cpp. The helpers of its anonymous namespace go to editormodetrackshared.h, as they were but inline, in namespace track_mode, which the files use. No line of code changes; the files add only their license, includes and the using line. * feat(editor): the groundwork the tools of the editor share - The tool interface (editortool.h), the gestures of the mouse (editorgestures.h) and what the modes share (editormodeshared.h); the projection, viewport, selection and texture picking taking them up. - Scripted input (scriptedinput): the input of a selftest script fed to the editor as if typed and clicked, the real mouse and keyboard ignored meanwhile; EU07_EDITOR_SELFTEST_HIDDEN draws into a window never shown nor focused. - The ui layers and panels of the editor, its settings, icons and the info of the includes; the layers of the scenery and their saving; the launcher mode. - utilities: user_cache_path (the cache folder of the system for the user) and the helpers of the translations. - stb_image: the gif loader takes the frame two back from the frames it decoded, not from before its buffer. - tools/editor: the scripts making the headers of the drives, the turntables, the editor and its usage. - Unit tests: test_area and the stubs of the editor the tests link. Not built on its own: the tree builds again with the selftests commit, the one before the translation. * feat(editor): the tracks laid along an alignment, to the PKP PLK norms, with their grade line and the ground - The alignment of the laying (editorAlignment, editorAlignmentStore): straights, transition curves and arcs with the cant of the norms for the speed, the radius below the minimum for it a warning; the lay, route and straights tools build on it, the route plan reading the curves going on from the tracks adjoining. - The grade line (editorProfile, the profile and gradeline tools): fitted to the terrain model or edited by hand, the tracks fitted marked in the scenery (//$f), the shared grade lines of nearly parallel tracks (//$n). - The ground under the tracks (editorGroundFollow, trackbed): the terrain drawn to the tracks and restored, the tracks put onto the terrain. - Connections between tracks (editorConnections, the connection and connection curve tools), the track presets, the shape of a track (editorTrackShape), digitizing tracks from the orthophoto, the properties sheet of the tracks (trackprops) and the track ux. - Unit tests: alignment, ground fit, heights, with the data of two fits. Not built on its own: the tree builds again with the selftests commit, the one before the translation. * feat(editor): the switches placed, slid and designed from their templates - The switch templates (editorSwitchStore, the template tool): the catalogue switches and the user's own, kept with the settings; the designer (editorSwitchDesign) with a drawing of the dimensions, a and b typed in with the shape making up the rest, a switch clicked off the orthophoto. - The curve of a switch laid into a curve (editorSwitchCurve), placement on a straight or into a curve, slide along it, crossovers and double slips (switchplace, switchslide), the drives of the switches (switchdrive) and the records of the switches placed (records). - Unit tests: test_switch_curve. Not built on its own: the tree builds again with the selftests commit, the one before the translation. * feat(editor): the tools of the infrastructure beside the tracks The gauge, speed, joints, lineside, parallel tracks, vehicles, signals, turntables, sweep and road tools with headers of their own; the kilometrage of the lines (editorKilometrage, the km tool); the infrastructure, roads and speeds behind them (editorInfra, editorRoad, editorSpeed). Not built on its own: the tree builds again with the selftests commit, the one before the translation. * feat(editor): the terrain model of geoportal.gov.pl and the orthophoto downloaded for the editor - editorNmt: the squares of the terrain model at 1 m (NMT GRID1, the WCS service of geoportal.gov.pl) fetched by two workers, kept in editor/cache/nmt/grid1 of the game folder, the heights of the scenery taken from them; the nmt mode loads it along the tracks or around the camera. - editorHttp: the HTTP client of both, WinHTTP on Windows, libcurl elsewhere where it's built with it; without it the caches only. - The orthophoto: its cache moved to the cache folder of the system for the user, the download area a polygon on the topo map (//$a) filled in the background, the 4K imagery, the tiles waiting outlined on the ground. - editorGeoMap: the topo map of the top view; heightmapterrain and the terrain streamer grow the terrain made from the model around the camera. Not built on its own: the tree builds again with the selftests commit, the one before the translation. * feat(launcher): the scenery wizard picks the place of a new scenery on the topo map the editor shares The wizard drops its own map download and decoding for the topo map widget of the editor (editorGeoMap). The place clicked becomes the geographic reference of the new scenery (//$g PUWG1992), and the scenery starts with the orthophoto of the editor on (//$o), lying under it in place. Not built on its own: the tree builds again with the selftests commit, the one before the translation. * feat(editor): the tools wired into the editor mode and the build editor_mode takes the tools of the commits before: its header declares them, editormode.cpp and the track mode drive them, and the renderers draw their overlays (opengl33 and legacy). CMakeLists lists the new sources and adds WITH_EDITOR_SELFTESTS (off by default); the unit tests build the new test files. Not built on its own: the tree builds again with the selftests commit, the one before the translation. * feat(editor): the selftests of the editor split by what they test The scripts of EU07_EDITOR_SELFTEST run the commands of editormodeselftest*.cpp: scene, track, rails, join, switch, signal, sleepers, sweep, terrain, monkey. The code is in every build; only with WITH_EDITOR_SELFTESTS=ON does the editor read the variables and run a script. The selftests of master now need the option too. The tree builds again with this commit. * feat(editor): the Polish texts of the editor, all of them in one update of editor_pl.po * fix(editor): the marks of the editor moved off the letters the starters read, and its lines told by their words The starters read some letters in a scenery file: the Starter the title //$n, the attachments //$f and the old scenery //$a, StarterNG and the launcher of the game the attachments //$f and the title //$n. The editor wrote its download area, shared grade lines and fitted tracks under them, and took every line of those marks as its own: saved, a scenery lost its title and attachments, and the starters showed the lines of the editor as them. - The download area is //$z, the shared grade lines //$w, the fitted tracks //$t. - Their lines and those of //$o are told by their first words, as //$h, //$r and //$k were: //$o only as "on 0" or "on 1", the origin or the settings of older builds after it, so a trainset described as "on ..." isn't taken. - The lines older builds wrote under //$a, //$n and //$f are read only by the words the editor wrote in them, or by its own comment line before them, under the new mark. Each save writes them again with it, also when the editor didn't change them; the lines of the starters stay. * fix(editor): a square of the terrain model cut short isn't read, and the squares are kept in the user's cache The service puts the directory of its GeoTIFF before the pixels, so a file cut short by a write or a fetch broken off was read whole, the pixels missing coming out as heights of 0 m, for good. - The reader (editorGeoTiff.hpp, with unit tests) wants all the strips the rows need, each within the file. - A square is written under a name of its own and renamed. - The squares are kept in the user's cache folder (nmt/grid1), as the orthophoto, since the game folder may not be writable; without one, in the game folder as before. The ones older builds kept there are moved over as each is asked for, a damaged one deleted. - Capabilities that didn't come aren't kept as the fallback name for the session: the next square asks again. * chore(editor): the http client said to serve the terrain model and the topo map too, the gif fix of stb_image marked local - CMake names the orthophoto, the terrain model and the topo map as what goes without libcurl. - The fix of the gif frame two back in stb_image is ours, not upstream's (v2.30 still has the old line): a comment at the line says so, for an update of stb_image to keep it. * fix(editor): the lines moved off the letters of the starters in a merged layer written once, not again with each save A merged layer's text goes into the file of its target on save, and the target is read again; the marked lines of the merged layer were dropped only for the marks the editor had changed. The lines moved to the new letters stayed with their old places, and the next save of the session wrote them into the target once more. - After a save, the marked lines of every merged layer are dropped; those of its target are read again from its file. - The lines of a dead layer aren't written again. - The selftest layermerge merges the layer of one file into another's, as the layers panel does. * feat(editor): the station as the signalling sees it, found from a switch of it, and its schematic editorStation: the switches joined by plain track no longer than 1.5 km, the tracks between them and the lines leading out, 400 m of each beyond the outermost switch; laid out as a schematic along the main track through the station. The track circuits, the signals and their lights, the lengths of the station tracks and the lines to the next stations are worked out from it for the signalling tool. Nothing uses it yet: the signalling tool, wired in the next commit, does. It builds on its own. * feat(editor): the signalling of a station in the Signalling tab, laid out from a switch of it as on the lines of PKP PLK LMB on a switch in the Signalling tab opens its station: the schematic in a window of its own, the name, the code, the line and the km of the station, and the steps of its signalling, each one step of undo: - the switches numbered along the station after its code, bpd_1, the parts of a slip bpd_15a..d; the drives and the objects naming a switch follow it, events written by hand keep the old names; - the tracks cut at the joints of the track circuits, Ie-4, and the circuits named, bpd_iz1, bpd_it1; - the entry, exit and shunting signals placed and named, A, F1, Tm1, from the templates chosen; - the signals of the lines out: the automatic block of three or four aspects, the block sections no shorter than the braking distance, or the semi-automatic one with a warning disc; block boundaries drawn by hand; - the lights each signal needs for its routes, Ie-1 and Ie-4 § 8, its template fitted to them; - the SHP track resonators the signals lack, rezonator.inc; - the lengths of the station tracks as a table, and what the station and its lines still lack, with Repair. The stations described are kept as //$s lines in the files of their layers. * fix(editor): the signals of a station and of its lines not placed with no template for a kind, no track cut for them first - Set the signals and Set the line signals cut the tracks first, and only then found no template for a kind. They stopped there, but the cuts stayed as a step of undo. Now they ask for the templates first, by the lookup signal_batch() uses (signal_template_for(), behind editor_signals::signal_templates_missing()). Without one nothing is cut. - Set the signals and Set the track circuits again under Track lengths had the ids of the buttons of the steps above them. ImGui flagged them when hovered. Each now has an id of its own. * fix(utilities): win1250_to_utf8 turns the polish letters into utf-8, not into themselves utilities.cpp starts with a byte order mark, so the compiler reads it as utf-8. The game's targets don't get /utf-8, though: set_target_properties(... COMPILE_OPTIONS ...) in the MSVC block of CMakeLists.txt replaces the options add_compile_options gave them. So the string literals went into the program in the code page of the system, windows-1250 on a polish one, and the map of win1250_to_utf8 turned each letter into itself. What read windows-1250 through it got no utf-8: the names, descriptions and categories of the sceneries and the names of the textures in the launcher, and the descriptions of the templates in the editor. The editor writes such a description back through utf8_to_win1250, which makes a question mark of each byte that doesn't start a utf-8 sequence, so the letters it had read unchanged didn't come back. The utf-8 sequences are written as bytes now, the way utf8_to_win1250 has them, so they don't depend on the options. The options stay as they are: with /utf-8 other literals of the files with a byte order mark would change, the "±" of the table of Bezogonkow would take two bytes and move the letters after it. The unit tests check the letters and that the text given is valid utf-8. (cherry picked from commit9ffed96ec1) * fix(editor): the switches renamed only after the events by their old names are shown, the station records in windows-1250 and in the file the scenery had Number the switches renames the switches and what the editor writes along with them, but not the events written by hand: a switch event aiming at a switch, or <name>:event0 and the others named after it, would keep the old name and lose its switch. Now the first click lists them in the status, up to six and how many more, and renames nothing. A second click with the same renames goes ahead. The name of a station is written in windows-1250, like the rest of the scenery file. A name read that isn't valid utf-8 is taken for windows-1250; the utf-8 the earlier builds wrote is read as it is. utf8_to_win1250 moves from editorIncludeInfo.cpp to the utilities, beside win1250_to_utf8, and the unit tests check both ways. The record of a station that had none goes beside the records of the other stations, in the file marked with them, so a scenery saved under another name keeps them in one file. output_layer takes, after <scenery>_<part>.scm, an included file of the part of another name, the one of the scenery it was copied from, before it makes a new one. The comments: the joints of the track circuits stand 4.2 m beyond the fouling points, where the axes are 3.5 m apart, as joints() counts them; the regulation of the lengths is cited with its date and title. * fix(editor): a scenery saved under another name keeps one file of the keys by the movable noses, not the old one beside its own The editor writes the keys by the movable noses on each save to <scenery>_dzioby.scm and includes it. A copy of a scenery, saved under another name, still included the file of the scenery it came from, and its save wrote a file of its own and included it too, so each key stood twice. Now the save leaves out of the scenery the other files of such keys it includes, told by the line the editor writes at their start. Their files stay on the disk, for the scenery they were made for. A file made by hand, without that line, stays included. The turntable controls had the same, fixed the same way on their own. * fix(editor): a file of the scenery named like a part of a tool isn't taken for the one the tool made output_layer took, after <scenery>_<part>.scm, any included file named *_<part>.scm, so that a scenery saved under another name goes on with the file of the scenery it was copied from. A file of the scenery named alike, written by hand, such as rejon_teren.scm, got the terrain directive, the hectometre posts or the new signals too. The files output_layer makes start with a line of their own now, "// scenery layer created in the editor for its <part> part", and a file of another name is taken only with that line. A layer gets it through the new parameter of scene::node_layers::create(); the others start with the general line as before. <scenery>_<part>.scm of the scenery itself is taken without the line, as it was. A file made for a part by an earlier build has only the general line, so a copy saved from it gets a file of its own. * feat(editor): a player of GIF clips for the windows of the editor editor_clips::clip plays a GIF in an ImGui window, looped, from the time given. stb_image decodes the whole file on a thread of its own, so the window isn't held up; until then the clip says it's loading. The frames are kept as stb_image decoded them, and the one shown is a texture of the ImGui renderer (Create_Image), made again only when the frame changes. A file that isn't there is told missing at once, with no thread started. Nothing uses it yet; the tutorial of the next commit shows its clips with it. * feat(editor): Help > Tutorial, fifteen short lessons of the editor The lessons: looking around, laying track, curves, the radius of the curves at the bends, correcting a curve, joining tracks, switches, switch templates, signals and posts, selecting and fixing, editing with the gizmo, the grade line, terrain from the terrain model, sceneries made before, saving and driving. Each lesson has: - in eight lessons, a looping clip from lang/editor_tutorial/<lesson>.gif, played from the start on a click; in six others, a moving drawing (the radius at a bend, a switch template clicked, the signals, the grade line, the terrain, a trainset); - the mouse buttons and keys drawn as pictures beside what they do; - ticks that fill in as the user does it, told by the tools through editor_guide::first_step_done(); - a button that turns the tool of the lesson on; - Back / Next and a dot per lesson, green when the lesson is done. The window follows the work: when the tool in use changes, it turns to the first lesson of that tool not done yet, and a page turned by hand stays until then. In a lesson of laying it warns when there's no ground under the cursor. Where it opens: - by itself when an editor session starts, until "Show when the editor opens" is unticked (first_steps in the editor's settings); - from the Help menu; - from a Tutorial button beside Lay a track in the hint of an empty scenery, which isn't drawn while the tutorial is open; - at its lesson, from a "?" by the radius at the bends in the lay panel. A lesson whose clip isn't there is shown without it; the clips aren't in this commit. editor_guide is a new role of the editor, given to the hekto-post and trainset tools. Selftest command tutorial <page>: opens the tutorial at a lesson, from 0; -1 closes it. * fix(editor): the lessons of the tutorial say what the editor does The lesson texts checked one by one against the tools; the ones that told otherwise: - Switches: a connection isn't chosen at the top of the panel, its kind comes from where the drag is let go (a crossover onto the other track, over a crossover the other way a double one, or scissors where they overlap). - Switches: a ladder leads onto the parallel tracks it's dragged across, let go on the farthest, with the straights up to where they start; it lays no missing tracks. - Terrain: there is no step 3. Step 1 is Location, step 2 is Load around the camera while there are no tracks and Tracks and terrain with its three ways once there are. The rows had the step numbers in the keys column, and 1, 2 and 3 switch the edit modes in the Terrain field. Now the steps show the mouse, the terrain under some tracks only is a row of F3 (the line the terrain panel shows), and the rows that only tell what the fit does have no key. - Sceneries made before: a plain include can be changed; the row lists what can't: an include template (.inc), the binary terrain cache, a file included twice or with parameters, a locked or hidden layer. - Laying: the second Esc drops the points only within 3 s. - The radius at the bends: two transition curves from 6000 m down to 2000 m while they're long enough for the speed, then an arc; a label turns orange where the curve breaks the norms, not because it came out smaller; two transitions meeting read 2xL and R; the labels of each transition curve are on laid tracks, close up. - Signals and posts: the W17 markers go by the selected switch, around the camera or the whole scenery, not along a line. - Selecting and fixing: E lengthens the track, the control vectors bend it. - The gizmo: at a point Q moves the point alone, W turns the whole track about it. The tooltip of Help > Tutorial no longer speaks of clips: the tutorial goes without them. lang/editor_pl.po has the new texts. * fix(editor): the lessons of the tutorial in plain words Every row, goal and warning of the tutorial is said again for someone who has never laid a track, in English and in Polish: - the words of the railway and of the editor are said in everyday ones, or explained where they come: the radius (how big the curve is), the transition curve (the easing into it), the cant (the outer rail raised), the gizmo (handles on the track), the control vectors (points that bend it), the grade line (how the line goes up and down), the terrain model (the real ground), the orthophoto (the aerial photo), the hectometre posts (every 100 m), W17 (how far a wagon may stand); - what only a designer needs is left out: the 6000 and 2000 m of the radius ladder, the compound curve, the hump, the kinds of include that can't be changed; - the buttons are named as the panels name them: Apply to the scenery, Template editor..., the tiles of the switch tool; - the Polish names of three lessons say what they are about ("Uchwyty na torze (gizmo)", "Wzniesienia i spadki", "Prawdziwy teren"). Their English titles stay, the lessons are found by them; - the warning of no ground under the cursor tells what happens to the track; - two captions of the drawings say what they show (the tracks inside a box, posts every 100 m), and in Polish the button of the top view is "Widok z góry (O)", without "ortogonalny". What each row tells of is the same as before. The msgid of the length typed while laying stays, the window of the keys (F1) uses it. * feat(editor): the semaphores and the warning discs chosen by what their descriptions say they show The descriptions of the signal templates can now say what a semaphore shows and what a disc repeats, and the editor reads it: - signal: {arms: 2, aspects: {Sr1: ..., Sr2: ..., Sr3: ..., Sz: ...}, repeats: {stop: ..., vmax: ..., "40": ...}} is kept with the template, the events named for each aspect - the palette shows a template with arms as a semaphore of its arms, with 1 arm / 2 arms and Sz picking the template of the same tile that has them - the signals of SRK take a semaphore whose aspects cover what the signal needs (Sr3 where a speed is reduced, Sz on the main signals), the fewest arms that do it, and say which one does when the placed one hasn't them or has more than it needs - the warning disc before a semaphore is one whose repeats cover stop, the highest speed and 40 km/h when the semaphore shows Sr3; SRK writes no events of the routes, so this only chooses and checks the disc - the linked signal (parameter 7) is read for the role link as well as text - signal_headers.py keeps the keys written by hand in a description (arms, aspects, repeats, the description and the parameters from 6 on) when it writes the guessed ones again - signaltemplates of the self test lists what the templates say and the heads made of them * feat(editor): the shaped discs swapped and set by hand, the warning discs checked by what they repeat The shaped shunting and stop discs (mk1, tzm, z1) are known to the signalling, but it doesn't place them by itself: - a shaped disc chosen in the palette for the shunting or the stop signals is placed by hand only; the signalling of a station takes the light template of the kind there, and says so when there is none - the template of a shunting or a stop signal standing can be swapped for a light or a shaped one of another mount as well (dwarf and mast, not gantry) - a signal whose description lists its aspects shows a button for each under its card: it sets the signal to that aspect in the editor, by the animations, the lights and the submodels its event sets off, the time standing still; nothing of it is saved. TAnimContainer::Finish takes an animation to its end at once, giving the submodel its angles, multi_event::branches tells the events set off when the condition isn't met From the review of the descriptions: - a shaped warning disc standing before a semaphore described is checked by the events it repeats: stop, the highest speed and 40 km/h of a second arm told apart; one which doesn't is offered the disc which does, and Fit swaps it - the disc offered is of the mount of the disc chosen, taken from the template even when it isn't described - 1 arm / 2 arms / Sz of the palette pick the template leaning as the chosen one and most like it by its name - a semaphore described with its arms but not its aspects has Sr1, Sr2 and with a second arm Sr3 - Fit leaves a semaphore having what it needs with its arms, for the events written by hand to the aspects of a second one; the messages of the fitting speak of what the signals need, not of their lights - signal_headers.py warns of a signal map written as a block, whose keys it can't keep * fix(editor): an aspect shown by hand doesn't name a vehicle that may be gone The Show button runs the events of the aspect outside the queue. run() writes the vehicle that set the event off last into the log, and nothing clears that pointer, so a train deleted since would have been read after it was freed. The queue sets the activator anew each time, so it is cleared before the run. * fix(editor): a disc not described is only offered the one that tells, a light stand-in of the mount of the shaped one - A shaped warning disc whose template doesn't say what it repeats may tell all its semaphore shows as well. It is no longer marked as not fitting: the disc described is offered as a hint, and Fit leaves it be. A disc whose template isn't among the scanned, its mount not known, is offered nothing rather than discs of any mount. - A shaped disc chosen for shunting or stop is stood in for by a light template of its own mount first, a dwarf for a dwarf. - The tooltip of the aspect buttons says the trains read the signal as its events set it last, in a run started from the editor too. - The Polish texts of the fitting speak of signals, not semaphores, since it takes the discs too. * refactor: the Sonar remarks on the switch blades taken care of - the big functions of the rails split into helpers with one job each: the carving, the laying and the planning of the rails, their crossings, the blades, the lofted spans of a segment, the profile of a rail measured piece by piece, the joining of the switches - the floating-point loop counters are while loops doing the same additions, so the samples come out where they did - C arrays are std::array, the two sides of the paths path_sides; the ends of a cut are two parts of one struct, ending and starting - the rail laid by a course of its own, not eleven parameters - the globals kept in functions, the nested ternaries taken apart, one declaration per statement, explicit captures, ranges algorithms, std::format, std::numbers, emplace_back, structured bindings - the region finds the sections around a point into a list the caller gives, so the search for the rails around a track shares no list with another thread - check_rails and create_track_rail_profile are const, the pool of the reused chunks can't be copied The geometry of every chunk of lk357 and td_fog, with the frogs on and off, comes out the same as before. * refactor: the Sonar remarks on the 3D sleepers taken care of - the big functions of the sleepers split into helpers with one job each: the clusters and the lines of timbers, the gaps under the rails, the models and their parts, the check of the layout, the drawing of the timbers in instanced batches - the tracks near a track found into a list of their own, the region searched into a list the caller keeps, not the one the region shares with the main thread; the callbacks are templates, not std::function - the layout of a cluster takes a span of its tracks - the globals kept in functions, the parts of a beam int constants, beam_overhang no longer hidden by a field of the same name - scoped_lock, jthread, contains, ranges algorithms, std::format, emplace_back, structured bindings, explicit captures, upper-case literal suffixes, one declaration per statement - the uniform buffer takes a span of bytes * fix(editor): the editor core builds with GCC again - kCrossoverStraights is constexpr, so the connection curve can take it into a constant expression; GCC refused a double that was only const there. - the track_hover alias inside editor_mode dropped: declared after hovered_track had already used the name, it changed what the name meant in the class (-Wchanges-meaning); the definitions name the shared track_hover. - <cstring> included where the rail self-test uses std::memcpy, which MSVC reached through other headers. * refactor: the second round of Sonar remarks on the switch blades - the carve of a throwable part takes the cut before it only where there is one, as only that cut makes it throwable - the splitting of a grooved profile by the floor of its groove moved out of the rail layer into a class of its own, which is given the profile, the size of the rail, the texture of the plates and the side - the rail drawing is made by a const function - the triangles of an ear-clipped outline go in as the arrays they are, the search for a corner within an ear is an any_of, the loop pruning thin corners keeps the count it started with, as it stops at the first - the bytes of the blocks of a texture are taken off the file through its buffer, with no cast of their storage - the log of a carved part takes the tracks around it as a span - the joint length of a switch, a constant, isn't captured, and the directions at the ends of a crossroads are tested in one condition each * refactor: the Sonar remarks on the tutorial - the window of the tutorial in smaller pieces: the steps reached, the lesson followed and its clip, the clip or the sketch of a lesson, its keys and steps, the button under it and the buttons of the pages; the lessons are a table of their own, the button of each kind of lesson picked from a switch - a clip whose delays add up to nothing shows no frame instead of dividing by them - the frames of a clip are decoded by a function of their own, on a thread kept with them and joined once it's done, or as the editor closes, instead of a detached one - the sleepers of the signal sketch counted by a whole number, the texts of the sketches made by std::format, their points kept in std::array, the whole numbers turned into floats where it's meant * fix: the bugs and vulnerabilities Sonar found in the editor core - the loops stepping along a track, a curve or the view count their steps by a whole number and take the station as so many steps from the first, instead of adding a fraction up, which drifts - the self-test of the guard rails keeps the plan of the rails of the track against while it goes through them: the range of the loop was in a plan made for it and gone before the loop began - the generators of the self-tests and of a unit test are seeded on purpose, so a run can be repeated: marked for Sonar as such - the tool writing the descriptions of the templates takes the names out of its tables only where they stay in the data folder * fix: the loops of the signalling stepping by a whole number the places of the block signals along a line and the marks of the chainage under the plan of a station are counted by a whole number and taken as so many steps from the first, instead of adding a fraction up, which drifts; Sonar took the counters of floats for bugs * refactor: the checks of the signal heads and the signal sheet in smaller pieces the remarks Sonar made on the signal descriptions: the warning about a disc on the mount of a signal is worked out by a function of its own, the fit and the aspects of a head, the swap of a template and its aspects in the sheet of a signal are drawn by members of their own, the walk over the events of a signal is a free function instead of a std::function held by a lambda, and the description of an include is read a part at a time; the names of the kinds are kept in a std::array and looked up by the algorithms of ranges, a name is taken as a std::string_view where it is only compared, and the locals named event, which hid the enumerator, are renamed * style: a space after a comma in the join self-test * style: a space after the question mark in the terrain sketch * style: a space after the question mark in the status of the fitting * refactor: the last Sonar remarks on the small fixes the opening of a scenario catches the exception the scenery throws when it can't be read, not any runtime error; the vehicle moved between trainsets keeps its source by a reference to const; the messages of a track of an unknown type and of a tributary are raw string literals; the parser opens a file by a std::filesystem::path, and the log of a file it can't open still names its folder and its name * refactor: the crossings of a track found without casting its const away the radius of a node can be read off a const one: radius_() is const across the nodes, the ones of the tracks and the models marked override, and a const radius() gives the radius worked out already, or works it out anew without keeping it; the helpers finding the crossings of a track only read it and take it const, its own run of rails typed apart from the ones of the tracks it crosses, which the crossings found name; the triangles of a filled outline are pushed as named corners * refactor: the paths around a track sampled without casting its const away the sampling of the paths and the clusters of tracks laid together only read the tracks, so they take and keep them const: the path sampled points at a const track, the tracks near one are found from a const one by its const radius, and a cluster holds const tracks; the shared zones of the timbers no longer cast the const of their track away * fix(editor): the Sonar blocker remarks on the stack, no side effects in the operands of && and ||, no local named final (S912, S1669) Counting the leftover signals, the pieces of a station walk, the places with nothing beside a run and the joints and fouling points logged by the self-tests no longer counts inside a condition; the last span of a straight is named tail. The counts and what they log are the same. * revert(vehicle): an axle on a switch follows the switch as it is set, as before the stack The axle kept to the path it came on, so a switch thrown under a moving train no longer sent the rest of it onto the other branch, and coming from the frog end it trailed shaped blades only where the wheels reached them. That changed the running of every switch in every scenery, and the AI still scans its route by the switch as set. TrkFoll is as on master again, and the trailing point of the blades it used is gone. * revert(track): a path is told a straight by its first control vector alone again, as the sceneries are made for A plain track was drawn bent where its second control vector was off the chord though the first lay along it, and a path with a radius given was never straightened. Tracks of existing sceneries drawn straight before would have been drawn bent, with their length, cant and the models along them. TTrack::straightened is the rule of master, for plain tracks and the paths of switches. The editor keeps a bend dragged with the second control vector, or set by joining the tangents, by moving the first one 2.5 cm off the chord to the side of the bend, past the tolerance, so the track is drawn, saved and read back bent, by older builds too; the second one dragged back along the chord takes the first one back onto it. * feat(track): the switches joined directly to other switches at load told in the log A switch right after another one is joined to it as the sceneries load, where its end was left open before and vehicles came off the track there. Each switch joined so is logged with its place and the number of ends, and the whole number once, so a scenery can be checked for places that run differently now. * fix(editor): a bend kept by lengthening the first control vector, not turning it keep_bent moved the first control vector 2.5 cm sideways, which turned the start tangent: a kink of 0.29 deg on a 15 m track, flagged by the joints check, and against the fixed direction at a switch or a locked track. Now the vector keeps its direction and gets 2.5 cm longer than a third of the chord, which the simulator no longer takes for a straight. It is also applied after an end is moved or snapped, since a new chord or a snap onto a neighbour could bring the vector back within the tolerance. With the second vector back on the chord, the first goes back to a third of it. * fix(track): each switch joined directly to another one logged with both names join_switches counted ends, while one join links both switches, and only the first switch of a pair was named. It now returns the switches joined to, and the log names both of each joint and gives the number of joints. * fix(editor): a path drawn bent is kept bent through every edit, one drawn straight is left as it is The first control vector is made longer past the 2 cm tolerance only where the path was drawn bent before the edit, or where the edit itself sets the second vector: the end of the path moved, its first vector, its second one, a neighbour followed or its grade taken, the controls aligned at a joint, an end snapped. A path drawn straight keeps being straight when its ends move, and the paths of a track that the edit doesn't bend aren't changed. Moving the second vector back along the chord takes the first one back to a third of the chord where it was made longer here. * fix(app): a scenery that can't be opened takes the game back to the launcher whatever the file system throws Catches std::runtime_error again, as master did: invalid_scenery_exception is one of them, and so is what the file system throws while the scenery is opened. * fix(track): the beams worked out in the background don't read the ends a switch is set to The ballast a switch trackbed takes is asked of the tracks joined to its main path, as the trackbed is made at the load, not of the ends the switch is set to now, which change as it's thrown while the thread runs. What the thread reads with no lock against the main thread is written down where it runs, with the two things driving can change: a switch thrown and a turntable turned. * perf(render): the cut faces of a track drawn with nothing put on the heap, a track with none passed over at once * chore(track): the switch drawing the cut faces in the unrolled material read only in the builds with the self-tests * docs(track): the blades flag said to be switched on, and what frogs in eu07.ini changes of it * fix(editor): a response over 64 MB is refused, curl kept to http and https, the address read as UTF-8 The body of a map or of a service the user typed is read into memory up to 64 MB and fails above that, with WinHTTP and with curl. curl follows at most 10 redirects and only to http or https. WinHTTP gets the address widened from UTF-8, so a pasted one with letters past ASCII isn't turned into garbage. * fix(editor): only the orthophoto an older editor kept is deleted from the settings folder, not all its cache The geoportal folder of the old cache is removed, and the cache folder itself only where nothing else is left in it. * fix(editor): the square metre of the outlined area written as its UTF-8 bytes, shown right where /utf-8 doesn't reach * docs(track): why the velocity read for a switch is put back after its segments are made * fix(track): the blade tips and the open ends of a track take the dark of the rail, not the colour of a worn tread No wheel runs over them, so their cut faces aren't drawn as worn: the beige the matte material gives a worn face is left to the cut faces of the frogs. * fix(editor): a neighbour followed or given its grade is bent only where its second vector really changed follow() and follow_grade() write the second vector of a track joined at its end back as it was when the joint didn't turn or keep its grade; a track the simulator draws straight with that vector off the chord was made bent then, though the edit never touched it. Its first vector is lengthened now only where the path was drawn bent or the second vector took another direction or grade. * fix(track): the open ends of a track laid with cuts take the dark of the rail too The rails a frog or a crossing cuts are laid piece by piece; the caps of their pieces at the open ends of the track were drawn worn with the cuts of the frogs. They aren't worn now, as the open ends of the other tracks. * fix(editor): a neighbour drawn straight is bent only where the edit took its second vector off the chord follow_grade() sets the height of the second vector anew on every graded joint, a fraction of a millimetre off the height the scenery has, so a change of the vector bent a track whose second vector stood off the chord sideways already, though the simulator draws it straight. follow() and follow_grade() keep a path drawn straight bent now only where its second vector lay along the chord before the edit and stands off it after; a path drawn bent is kept bent as before. How far the vector stands off the chord is measured in one place, keep_bent() uses it too. * docs(editor): the comment of keep_bent above keep_bent again, not above the measure of the chord * Editor: signal reads kept by the signal, level crossing discs, signals out of the gauge, indicators, the signalling tools split (#307) * fix(editor): the read of a signal stays by it as its track is split, on a switch and when it is moved, and a level crossing disc is placed The trains find a signal by its read, a passive event in a list of the track, and measure the way to the cell it reads along three tracks further at most. The editor let the read drift away from the signal, or put it where trains of another path read it. - A track split in two: a read the trains scan for (a passive event) goes to the piece by the point it reads, whatever its list; before, those of the runs towards the end stayed on the first piece. Five splits left the reads of A, B, C and J on the first piece while the signals stood on the sixth, out of the reach of the trains. The reads of signals placed since the scenery was opened, not bound to an event yet, go to the piece by their signal the same way. - A signal moved off its track jumped back to that track's end once the track was changed: the track had taken it up as its object and measured it again along itself. A moved signal is let go by the track it stood by, and an object of a single point moved off the side of its track no longer follows it. - A switch reads its events to the trains of both its paths. A signal past the frog of a path, where the axes are a gauge apart, is passed by the trains of that path only, so its read goes to the track joined to the far end of the path, in the list of the trains running from the switch onto it or the other way. Before the frog it stays on the switch. Moving the signal across the frog takes the read between the two. - A signal by a switch on the side of its other path stood on that path, in the way of its trains (0.45 m from its axis); it is refused there, placed or moved, with the reason. - The kind crossing of the descriptions (tsosp, tsospn) is known: the level crossing disc is listed in the palette and placed with its read. Checked in the editor on a hidden desktop: five splits of a track with bound and fresh reads, a signal moved to another track and the old one raised, signals placed before and past the frog of a switch on both paths, turned and moved across the frog, saved and opened again with the reads bound, the tracks raised, shifted and bent with the signals following. Unit tests pass. * fix(editor): a split keeps reads far off the path and bound objects up to 30 m by their pieces A read the trains scan for moves to the piece by the point it reads only from event1 and event2, only when it isn't ignored and only when that point is within 50 m of one of the pieces; a read at the station building stays in its list. An object bound by hand keeps its binding as its path moves up to 30 m from it, an adopted one up to 12 m as before. * feat(editor): the tracks that read a signal are drawn and can be picked, flipped or dropped The selected signal shows each read of its _sem_info as a thick band over the reading track, arrows in the way the read is scanned, a line from the foot of the signal and a plate with the list and the track; the hovered one shows them thinner and placing or moving a signal shows where it will be read. The panel lists the reads: each can be turned the other way or removed, "Pick the path" takes a click on a track (with Shift one read more or less) and "By the path it stands by" puts back the read the signal gets when it is placed. Each change is one step of the undo. The self-test gets signalread, signalreadflip, signalreaddrop and signalreaddefault, and the probe lists every read of a signal. * fix(editor): a moved or turned signal keeps the reads picked by hand, and a read set again isn't an undo step Moving a signal, taking it across the track or turning it put back only the read by the track it stands by and dropped the others: those stay on their tracks now, on the other list when the signal is turned. Setting the reads the signal has already says so and adds no step to the undo. Picking a reading track disarms the template, so a click after Esc doesn't place a signal, and the signals are listed again after any change of the history, also once it is full. * feat(editor): a signal is placed out of the gauge of the tracks around it As a signal is placed, moved, taken across or turned, its models are measured against the gauge chosen in the Gauge window along every path near it. One that enters it is taken sideways, away from the axis of the track whose gauge it enters, as deep as it went in and 3 cm more, in the same step of the undo; between two tracks too close for it, it stays where it was put and the status tells which gauge it enters and how deep. A gantry is only measured. The panel of the selected signal tells when it stands in the gauge, with a button to move it out, and the view marks the deepest place. The gauge tool measures any models against the paths around them for it. The self-test places a signal at a given offset and its probe tells the gauge. * fix(editor): a moved signal leaves only the read of the track it stood by, and the gauge is checked on its level The reads a moved signal keeps were all but the first one listed, which is the first track of the scenery having it, not the one the signal stood by: a read picked by hand could go and the track it left could keep it. It is the read of the track it stood by that goes with it now, and turned, eventall1 and eventall2 swap as well. A track more than 2 m above or below the foot doesn't push the signal aside, the status tells the real distance it went, the gauge is measured again when the signal follows a dragged track, and the marker in the view shows only what is up to date. * feat(editor): indicators put on a signal from the panel, they move and go with it The indicators of scenery/pkp/wskazniki described as "category: indicator" are offered under the selected signal, grouped by their sign. One is put in as an include named after the signal, on the srk layer: - a lit one (place: head) under the lowest lamp of the signal, 0.73 m below it and 5 cm ahead of the mast, each next one 0.45 m lower; a dwarf signal is refused, it has no mast for one; - a plate (place: foot) at the foot of the signal, its model has its place by the mast built in. The panel lists the indicators standing by the signal with a Remove button. They are found as the includes whose first parameter is the signal's name, within 1 m of it in plan. When the signal is flipped, turned or moved, they keep their place in its frame, in the same undo step; deleting the signal deletes them too. If the signal and the indicator both define an event, the status says so, since the scenery keeps only one of them. The self-test gets signalindicator and signalindicatordrop, and its signalprobe gives each indicator's height and the height of the lowest lamp. * feat(tools): indicator descriptions and the indicators taken out of the signal templates indicator_headers.py writes //$e descriptions into the LED indicators of scenery/pkp/wskazniki (W19, W20, W21, W24, W26) with the events each shows. It also makes the indicators that were so far only built into the signal templates: - W1 of the warning discs, new, old and with the light strip; - W1 and W18 (new and old) of the block signals; - the I, II and III plates of the repeaters. The plates fixed flat to the mast are moved 4 cm ahead. Their back is 5 cm from the mast's axis, while the mast is 6.1 cm thick and its clamp under them 8.3 cm, so the mast went through the plate, in the templates too. * fix(editor): a signal turned or moved by the gizmo is read and kept out of the gauge, its indicators go with it everywhere The gizmo of an include only rewrote the numbers of a signal. Its read stayed on the event it had, even when the signal was turned to the trains of the other direction. Its indicators stayed behind, its height could be dragged off the ground, and the gauge wasn't checked. Now: - the gizmo moves a signal in the plan only, at the height it has; - while it is dragged, its indicators keep their place by it; - once it is let go, the drag is made again as a move of the signal tool, one step of the history: the read goes to the event of the trains it faces on the path it stands by, and it is taken out of the gauge; - dropped away from every track, it goes back where it stood. The indicators of a signal are found in the scenery now, not in the list the signal tool keeps up only while it is open: - deleted from another tab, the signal takes them with it; - a signal renamed in the node properties gives its new name to them in the same step of the history; - in the station and line batches, a renamed signal renames them, and a removed one removes them; - the binding of objects to tracks puts them on the path reading their signal, not on the one nearest to them, and a signal moved by hand lets go of them too. Also: - a signal on a gantry takes no indicator from the list; - an indicator a signal has already isn't put on it twice; - the signals and their indicators are found in one pass over the includes, the indicators by the name of their signal; - a step of the history with tracks is always one of their edit, so they are taken back with the includes. The self-test gets signalgizmo, which turns and moves a signal as the gizmo does. * fix(tools): indicator_headers.py keeps the files it replaces, writes beside the data on request - An indicator it made, found changed, is put into a tar in editor_backup before it's written again. - --sidecar writes the descriptions of the lit indicators into editor/templates, as the other header scripts do, the files of the game left alone. - The indicators it makes are copies: the signal templates keep their own, and the docstring and the files say so. * fix(editor): a signal moved by the gizmo by another track is read by it, the templates known without the signal tool - At the end of a gizmo move the nearest track takes the signal when it is nearer than its own by more than 0.5 m; a track it was dropped onto, within 1.2 m of its axis, doesn't, so a signal only turned between two tracks or dropped onto one in a switch keeps its own. - The signal templates and indicators are looked for when a signal is renamed or its gizmo shown, so its indicators follow without the signal tool opened first. - A drop refused puts the gizmo and the node properties back where the signal stands. - The indicators follow only once the gizmo made its step, and the ones not changed are left alone: grabbed and let go it changes nothing. * fix(editor): a signal dropped by the gizmo onto a track keeps its own, the gizmo doesn't wait for the template scan - When the nearest path to the drop is within 1.2 m of its axis, the signal keeps its own track, instead of only that path being left out: dropped onto a middle track it no longer goes to the track beyond it. - The gizmo starts the signal template scan without waiting for it, so a rescan with a signal selected doesn't stop the editor; renaming a signal still waits. * feat(editor): the signalling split into Signals, Station, Station signals and Line block The one Signalling tool held the signals placed by hand, the whole wizard of a station and its checks; each is now a tool of its own in the toolbar: - Signals (I): the palette, a signal placed by a track, dragged along it, selected; a click on a switch no longer opens a station. - Station: LMB on a switch lays the station out; its name, code, line, km, speed and braking distance, the numbers of the switches, the track circuits, the number of the selected track, the list of the switches. - Station signals: the signals of the whole station placed at once, the template of each of their kinds (main, shunt) chosen in a table, and below what the signalling lacks: the repairs, the SHP resonators, the track lengths, the signal heads. - Line block: the block of each line, the block boundaries drawn by hand, the line signals, the templates of the block signals and warning discs. The station tools share the open station and its schematic; Station signals and Line block show what the Station tool set for it, the line and the km in red where the line block needs them. The template table replaces the palette in the station tools, so choosing a template there no longer arms placing. Two icons drawn for the new tools, in editor_icons.py too; the png is drawn by the same shapes, Pillow wasn't at hand. The tracktab self-test takes a tool by its name, and srkopen shows the Station tool. * feat(editor): a signal shows its distance from the track axis and to the switch ahead, and goes to 50, 100 m... from it - editor/editorTrackTrace: the track followed the way a train runs, shared by the W17 markers and the signals. The fouling point of a switch (where the axes of its tracks are 3.5 m apart) moved here… * fix: a failed start says why and ends with an error code; a small crash dump by default (#425) * fix: a failed start says why in the log and ends with an error code When the window could not be made, the log only said "Bad init: failed to create glfw window", without the reason glfw knows (no OpenGL driver, no pixel format that fits, no EGL). Sometimes it did not even say that: the log thread writes every 50 ms, and main() ended the process with std::_Exit(0) without stopping it, so a start that failed within that time left a log that ends at "// startup". - glfw's errors go to the log and errors.txt through glfwSetErrorCallback, set before glfwInit(); each distinct message once. - after a failed start (or an exception caught in main) the log thread is stopped and waited for, as the test runs already do, so nothing logged last is lost. - a failed start ends with exit code 1 instead of 0, so the starter can tell it from a closing. A start that worked ends as before. * fix: glfw's errors told during the start only, a closed crash dialog is no failed start After review of the previous commit: - the glfw error callback is taken off at the end of init(). Once the simulator runs, glfw would only repeat what the platform can't do (glfwSetCursorPos on Wayland, on every mouse-look) or what a scenery asks for in vain (launcher key codes below GLFW_KEY_SPACE, checked on every update), which would put new lines in errors.txt of existing sceneries and cost a format and a lock per call. - closing the crash-report window ends the simulator as before, but init() now returns 1 for it (above 0: closed by the player), and only a result below 0 gives exit code 1. - a start that throws from init() (bad_alloc, or a runtime_error on Windows) ends with exit code 1 too; an exception after a start that worked ends with 0 as before. * feat: a small crash dump by default, the full one with "crashdump.full yes" The dump written by the crash handler (Windows, WITHDUMPGEN) held all the memory of the simulator (MiniDumpWithFullMemory), so it was as large as the memory the simulator took: gigabytes on a large scenery, written to the game folder at the moment of the crash, on machines with 8 GB of RAM too. By default it now holds the stacks with the memory they point to, the threads, the modules, the handles, the memory map and the modules' data segments (MiniDumpWithDataSegs in place of MiniDumpWithFullMemory, the rest of the flags as before). The globals, Global among them, stay readable. "crashdump.full yes" in eu07.ini writes the full dump as before. Measured on td.scn with a ghostview camera (1.2 GB committed): the small dump 44 MB in 2 s, the full one 1.6 GB in 19 s. The key is new and optional: eu07.ini files without it read as before, and the setting is listed in the log at start. * fix: the small crash dump keeps the process and thread blocks MiniDumpWithProcessThreadData adds the PEB and the TEBs, a few KB: the command line (the scenery and the vehicle), the environment and the last error of each thread, which the small dump otherwise lacks, since the heap behind Global's longer strings is not in it. * fix: an exception that ends the simulator says what it was in the log After review of #425: - the exceptions main() catches are logged ("Critical error: ..."): on Windows the runtime_error that only showed a message box, and on the other systems any std::exception, which used to end the simulator through std::terminate with no word in the log. On Windows the others are still left to CrashHandler, whose dump shows where they were thrown. - every exception caught there ends with exit code 1, in the start or later, as a crash; it used to be 0 when caught, the abort code when not. - closing the crash-report window logs "Crash report window closed, closing" instead of the error "Failed to run crash gui!", which stays for a result below 0. * feat: the stack of a crash on Linux in the log and on the standard error On Linux no dump is written (the crash handler is Windows only, crashpad is off), so a crash left a log that just stopped. A handler of SIGSEGV, SIGBUS, SIGFPE, SIGILL and SIGABRT (installed at the start of main) now writes, with write() only: Crash: signal 11 (SIGSEGV) at address 0x... Version: EU07 (cmake), <hash> (...) Stack (addr2line -f -C -e <the eu07 file of this version> <offset>): <backtrace_symbols_fd> to the end of the log file (its whole path, set when the log opens it) and to the standard error, which StarterNG shows first. The Linux builds carry their symbols (GENERATE_PDB adds -g, nothing strips them), so addr2line on the eu07 file of the same version gives the files and lines. Then the signal ends the process as before (SA_RESETHAND, raise): the same exit status, and a core dump where the system makes one. The handler runs on an alternate stack, so an overflow of the main thread's stack is reported too; backtrace() is warmed up at install so it doesn't allocate in the handler, and alarm(5) ends a handler that hangs (a crash in the allocator or the loader). WAMR is built without its hardware bound checks, so it installs no SIGSEGV handler of its own. Elsewhere crash_signals does nothing. A unit test (Linux only) crashes a child process and checks the report on its standard error and in the log, and that the child still ended by SIGSEGV. * fix: the crash report can't be cut by a second crash signal or end with SIGALRM After review: - the five crash signals are blocked while a report is written, so a second one waits rather than starting a second report in its middle (a fault that comes while blocked still ends the process). - a report that hangs past alarm(5) ends the process by the signal of the crash, not by SIGALRM: a SIGALRM handler, set only in the crash handler, raises the crash signal and unblocks it. - the child of the unit test calls alarm(10) first, so a child stuck before the crash can't hang the build. --------- Co-authored-by: maj00r <maj00r@host> * feat(track): unevenness waves shaped by the track spectra of FRA and ORE B176 (#426) * feat(track): unevenness waves shaped by the track spectra of FRA and ORE B176 The waves were 5-42 m sideways and 8-83 m vertically, with the long ones cut down, so a short wavelength carried a large share and the ride and the rails looked busy. They are now 7-90 m sideways and 8-110 m vertically, about the bands D1-D3 of EN 13848, each wave standing for a band of the spectrum S ~ Wc^2 / (W^2 (W^2 + Wc^2)), Wc = 0.8245 rad/m, the shape the FRA and the ORE B176 (German) spectra share: the longer a wave, the higher it is. The "uneven" value keeps its meaning, the peak deviation of a rail on a 10 m chord as PLK Id-14 measures it, so the values in sceneries stay as they are. Since the chord sees the long waves less, the amplitudes are calibrated again, and apart for the vertical and the sideways waves: stray_per_mm becomes stray_up_per_mm 0.00229 and stray_side_per_mm 0.0031, and cross_share 0.35. A track at "uneven 18" measures 18 mm vertically, 17 sideways, 15 of twist, +-10 of gauge, 21 of cross level and J 5.7 against the Id-14 limits for 80 km/h. A rail now goes up to about 5 cm off its design over the long waves, so the bound of the test goes from 40 to 60 mm; the short waves the cab shakes on are smaller, the sideways bend under the axles about 30% less. Every scenery with unevenness looks and rides differently after this. No release has unevenness yet. The grading tool follows the vertical waves; on Baltyk the pantograph keeps within 0.6 cm of the wire up to the product 1150 of the vertical value and the speed (925 before). * test(track): bound the sideways offset of an uneven track off its design The longer waves move the track about 4.5 cm sideways off its design at "uneven 18" (2 cm before), and nothing checked or stated it. The Id-14 test now bounds the peak sideways offset of the middle of the track below 5 cm, next to the vertical one, so a later change of the shares can't double it unnoticed. The doc gives the figure, and names platform edges and level crossing panels among what a rail moves away from. --------- Co-authored-by: maj00r <maj00r@host> * feat(editor): ~ shows or hides the orthophoto, Ctrl+~ downloads what the camera sees first; the speed of the camera in the View menu (#312) * feat(editor): ~ shows or hides the orthophoto, Ctrl+~ downloads what the camera sees first; the speed of the camera in the View menu ~ (the key left of 1) turns the orthophoto on and off. Ctrl+~ finds what of the ground the camera sees (rays through a grid over the screen down to the level of the ground under the camera, or as far as 2.5 km where they don't come down to it) and puts those tiles at the front of the queue of the downloads, the ones which failed tried again at once; the status line tells how many. Tab is not used, the laying and the switches have it. View > Camera speed: the speed of the free camera of the editor (x0.05 to x10, 1 as it was), how many times faster Ctrl makes it (1 to 30, 30 as it was), and in the top view as fast as the view is zoomed, so the map crosses the screen at the same pace zoomed in or out. Kept in the settings of the editor; the camera of the cab and of the free fly outside the editor unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DDcMn1Q7wdYkbxDUWscNHZ * fix(editor): Ctrl+~ in the top view, over a scenery with no terrain under the camera and with the orthophoto off; "As it was" without the speed going with the zoom In the top view the box is the view itself, its corners on the ground. The ground under the camera is the terrain, else the scenery, else the rays go as far as the reach. The tile of the camera is taken anew by hurry(), it isn't followed while the layer is off. The top view is as fast zoomed in as out by default, as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DDcMn1Q7wdYkbxDUWscNHZ * fix(editor): the corners of the top view on the ground put where the camera is (the view matrix is camera-relative) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DDcMn1Q7wdYkbxDUWscNHZ * i18n(editor): Polish for the orthophoto keys and the camera speed, on top of the master's own translations Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DDcMn1Q7wdYkbxDUWscNHZ * fix(editor): Ctrl+~ asks only for the tiles update() would ask for; the tooltip of "Track colours" back in its place After the reviews of #312: - hurry() skips the tiles outside the download area set and marks the ones outside the area the service covers as empty, as update() does, so Ctrl+~ no longer queues downloads update() drops at once (and the workers took anyway, into the disk cache, against the area set), nor requests the service can't answer. - A blank tile hurried takes the standard image first, as in update(); first_level() and outside_area() are shared by both loops, and the body of the loop of hurry() is hurry_tile(). - orthophoto_hurry() takes the level of the terrain only when it's below the camera, as the branch of the scenery already did: a camera under the terrain (a tunnel, under the heightmap) no longer flips the box of the view behind it. - The "Camera speed" menu goes after the tooltip of "Track colours", which it had taken. - #include <set> once in editorOrthophoto.hpp. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QRgQ1K1Qu7TCsa74zsNURd --------- Co-authored-by: Claude <noreply@anthropic.com> * fix: whole-number bounds of Random() give a real number again (#416) * fix: whole-number bounds of Random() give a real number againee3af0bf(#99, in 26.05.2) renamed RandomInt to an overload, Random(int, int). The calls with whole-number bounds that expect a real number in between took the overload and draw whole numbers since: - wheel flats given with P0 happen to 1 vehicle in 101 (before: none), the random part of a flat is a whole number of millimetres; - the chance of truck hunting is h/101 instead of h/100; - the wind starts with a whole azimuth, speed and rates of change, and its direction changes in whole degrees per second; - the tachometer below 5 km/h jumps to whole numbers. The whole-number draw is RandomInt again, keeping the shared engine and the swap of inverted bounds; the loading screen's trivia use it. Those calls take the real Random() again, as up to 26.05.1. * RandomInt: the comment says what it draws and why it has a name of its own The comment put the bug on the overloading. It was in the calls that pass whole-number bounds and expect a real number; the separate name keeps them on Random(double, double). * fix: RandomInt draws from the local engine, as up to 26.05.1 from one of its own From the review of #416:ee3af0bfmoved RandomInt from an engine of its own (std::mt19937 seeded by std::random_device) to Global.random_engine, the engine of the run's seed, and only the name was taken back here. Its one caller draws the trivia of the loading screen, in init_modes, before a network client gets the seed of the session in server_hello: the server's engine was then one draw ahead of the client's, and with a fixed randomseed the trivia was the same on every start. It is drawn from Global.local_random_engine now, the engine of what one machine shows, seeded from a true random source in init_modes before the loader is made. The test of the same seed checks the shared engine with Random() and the local one with RandomInt(); a new test checks that RandomInt() doesn't move the engine of the run's seed. --------- Co-authored-by: maj00r <maj00r@host> * fix(editor): the orthophoto only on the chunks of the heightmap terrain in memory, and laid onto the ground again once it comes (#417) * fix(editor): the orthophoto only on the chunks of the heightmap terrain in memory, and laid onto the ground again once it comes Right after the editor started, the tiles of the orthophoto came from the disk cache at once and were fitted to the ground before the chunks of the heightmap terrain had come (on IRT the orthophoto was on at 24.5 s, the first chunk came at 24.5 s, the last one at 85 s). A tile with no ground under it, and none beside, stayed flat at the height of the layer (0 m, some 230 m under IRT); one partly over the ground had its holes filled from the points beside. Neither was fitted again when the ground came: only the guessed tiles were, by their middle and corners alone, and a tile with no chunk under it at all never got any. The overlay, drawn over everything, then slid with the camera (WASD, turning) instead of lying on the ground. Turning the orthophoto off and on hid it: by then the terrain was in and the tiles took their heights from it or from the edges of the tiles beside. - With the heightmap terrain (the terrain streamer active), a tile of the orthophoto, of the WMS layers and of Ctrl+~ is asked for and shown only where its chunks are in memory (terrain_streamer::ground_under): it waits while one is still to come, and where no chunk is nor will be there's no imagery at all. A scenery without the heightmap terrain is as before. - A tile remembers the points of its grid the ground didn't answer and is fitted again once the ground comes under any of them (every second point and the edges), not only the guessed tiles. No asset changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(editor): the orthophoto waits only for the chunks that will come at this distance, and lies on the other ground or the guess elsewhere After the reviews of maj00r and jerrrrycho on #417: - A tile is no longer dropped where no chunk of the heightmap terrain is nor will be. There it lies on whatever ground there is (terrain models) or on the NMT guess, as on master; a scenery with a few chunks, or with chunks removed, keeps its imagery around them. - A chunk counts as still to come only while it's being loaded or lies within the circle the streamer walks around the camera. The corners of the imagery in the 3D view, beyond that circle, no longer wait for chunks that won't load there: they lie on the guess and are sampled again when the camera comes near and the chunk loads. - terrain_streamer::ground_under() (true / false / empty) became ground_coming() (bool), the cover source of the orthophoto the coming source, and on_ground() waits_for_ground(), which only holds back a new tile. - In the scene (in_scene), the points a steep triangle leaves without a height but the heightmap terrain answers aren't kept as unanswered, so the tile isn't sampled again on every chunk that comes. The holes are counted from the heights again, as on master. --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> * fix(editor): the closing doesn't wait for a geoportal service that doesn't answer (#432) * fix(editor): the closing doesn't wait for a geoportal service that doesn't answer When geoportal.gov.pl took the connection and never answered, the editor's closing stood still for tens of seconds and was killed: the WinHTTP client was synchronous and looked at the stop only between the reads of a body, so a request waiting for the answer held the closing for the timeouts (up to 20 s for the answer, a few tries a square), and the map of the place-picker downloaded with no stop at all, its std::async future waited for to the end. On Windows the client now uses WinHTTP asynchronously: each step is waited for while the stop is looked at every 50 ms, and a stop closes the request at once. The timeouts, the user agent, the size limit, the errors and the body of a response with an error status stay as they were. The map of the place-picker is given up when it goes. libcurl looked at the stop during the whole transfer already. The unit tests run the client against a local server that never answers (given up within 0.4 s of the stop), one with a body of 100 kB and one with an error status. * fix(editor): the capabilities of a WMS service being added don't hold the closing either The reading of the layers of a WMS service the user adds ran on a std::async future of the editor with no stop: closing the editor while such a service didn't answer waited for its three tries. The reading is given up when the editor goes, as the other downloads now are, and editor_http_get, left with no callers, goes. The unit test's silent server no longer waits for the client to close its connection, and the requests to the local server are skipped when the environment names a proxy, which couldn't reach it. * fix(editor): the stop of the WMS reading outlives the future waiting for it The flag was declared after the future of the reading, so it was destroyed first while the future's destructor still waited for the task reading it. --------- Co-authored-by: maj00r <maj00r@host> * revert(environment): the turbidity of the sky as it was before #227 (#410) #227 (842b7688) raised the turbidity of the sky dome for most cloud covers (3 -> 4 for a clear sky, 5 -> 6 at 0.41-0.60, one more from 0.61 up to 0.90). In the Preetham model a higher turbidity darkens the sky a lot once the sun is below the horizon: with a cover of 0.47 the zenith is about a third darker 1.4 degrees below it and half as bright 3 degrees below, the stars come out right after the sunset and the ambient light taken from the sky dome drops with it. Players report the dusk as too dark since the update. The values are put back as they were before #227, in the turbidity_of() that #323 made of the old chain of conditionals. A clear sky gets the turbidity 3 again, which #227 said breaks the model at night. Co-authored-by: maj00r <maj00r@host> * Revert "fix(physicslog): no road-vehicle logs, formatting on the writer, a slow disk and the closing kept short (#408)" This reverts commitd6c3593520. --------- Co-authored-by: maj00r <73280030+maj00r@users.noreply.github.com> Co-authored-by: maj00r <maj00r@host> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Hirek193 <polomarket73@gmail.com> Co-authored-by: pol102 <mindak.m@icloud.com>
3579 lines
189 KiB
C++
3579 lines
189 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/.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include "application/applicationmode.h"
|
|
#include "application/editoruipanels.h"
|
|
#include "input/editormouseinput.h"
|
|
#include "input/editorkeyboardinput.h"
|
|
#include "vehicle/Camera.h"
|
|
#include "application/editormodegauge.h"
|
|
#include "application/editormoderide.h"
|
|
#include "application/editormodeminimap.h"
|
|
#include "application/editormodejoints.h"
|
|
#include "application/editormodelineside.h"
|
|
#include "application/editormodeparallel.h"
|
|
#include "application/editormodespeed.h"
|
|
#include "application/editormodesrk.h"
|
|
#include "application/editormodekm.h"
|
|
#include "application/editormodevehicle.h"
|
|
#include "application/editortool.h"
|
|
#include "scene/sceneeditor.h"
|
|
#include "scene/scenenode.h"
|
|
#include "editor/editorTerrain.hpp"
|
|
#include "editor/editorTerrainStreamer.hpp"
|
|
#include "editor/editorOrthophoto.hpp"
|
|
#include "editor/editorNmt.hpp"
|
|
#include "editor/editorGeoMap.hpp"
|
|
#include "editor/editorTrack.hpp"
|
|
#include "editor/editorTrackTrace.hpp"
|
|
#include "editor/editorConnections.hpp"
|
|
#include "editor/editorAlignment.hpp"
|
|
#include "editor/editorAlignmentStore.hpp"
|
|
#include "editor/editorSwitchStore.hpp"
|
|
#include "editor/editorSwitchCurve.hpp"
|
|
#include "editor/editorKilometrage.hpp"
|
|
#include "editor/editorSpeed.hpp"
|
|
#include "editor/editorRoad.hpp"
|
|
#include "editor/editorProfile.hpp"
|
|
#include "editor/editorGroundFollow.hpp"
|
|
#include "editor/editorInfra.hpp"
|
|
#include "editor/editorGauge.hpp"
|
|
#include "editor/editorClips.hpp"
|
|
#include "editor/editorIcons.hpp"
|
|
#include "application/scriptedinput.h"
|
|
#include "world/Sweep.h"
|
|
|
|
#include <array>
|
|
#include <map>
|
|
#include <tuple>
|
|
#include <chrono>
|
|
#include <functional>
|
|
#include <atomic>
|
|
#include <future>
|
|
#include <memory>
|
|
#include <optional>
|
|
#include <sstream>
|
|
#include <limits>
|
|
#include <set>
|
|
#include <string>
|
|
#include <string_view>
|
|
#include <vector>
|
|
|
|
class TAnimModel;
|
|
// a tool of a field of work of the editor, a button in the toolbar and over the 3d view
|
|
struct editor_tool_button;
|
|
class TTrack;
|
|
|
|
class editor_mode : public application_mode, private editor_track::observer, private editor_services
|
|
{
|
|
|
|
public:
|
|
// constructors
|
|
editor_mode();
|
|
~editor_mode() override;
|
|
// methods
|
|
// initializes internal data structures of the mode. returns: true on success, false otherwise
|
|
bool init() override;
|
|
// mode-specific update of simulation data. returns: false on error, true otherwise
|
|
bool update() override;
|
|
// maintenance method, called when the mode is activated
|
|
void enter() override;
|
|
// maintenance method, called when the mode is deactivated
|
|
void exit() override;
|
|
// input handlers
|
|
void on_key(int Key, int Scancode, int Action, int Mods) override;
|
|
void on_cursor_pos(double Horizontal, double Vertical) override;
|
|
void on_mouse_button(int Button, int Action, int Mods) override;
|
|
void on_scroll(double const Xoffset, double const Yoffset) override;
|
|
void on_window_resize(int w, int h) override
|
|
{
|
|
;
|
|
}
|
|
void on_event_poll() override;
|
|
bool is_command_processor() const override;
|
|
// takes the last change back; changes made together (e.g. to the models of a selection) are taken back together
|
|
void undo_last();
|
|
static bool focus_active();
|
|
static void set_focus_active(bool isActive);
|
|
static TCamera& get_camera() { return Camera; }
|
|
static glm::mat4 projection_matrix(float const Aspect);
|
|
void toggle_ortho();
|
|
static bool change_history() { return m_change_history; }
|
|
static void set_change_history(bool enabled) { m_change_history = enabled; }
|
|
static bool settings_open() { return m_settings_open; }
|
|
static void set_settings_open(bool enabled) { m_settings_open = enabled; }
|
|
private:
|
|
// types
|
|
struct editormode_input
|
|
{
|
|
|
|
editormouse_input mouse;
|
|
editorkeyboard_input keyboard;
|
|
|
|
bool init();
|
|
void poll();
|
|
};
|
|
|
|
struct state_backup
|
|
{
|
|
|
|
TCamera camera;
|
|
bool freefly;
|
|
bool picking;
|
|
};
|
|
|
|
struct stored_profile;
|
|
struct EditorSnapshot
|
|
{
|
|
enum class Action { Move, Rotate, Scale, Add, Delete, TrackEdit, Other, RoadEdit, Array, Bend, Terrain, Kilometrage };
|
|
// copy of a model an array made
|
|
struct array_copy
|
|
{
|
|
TAnimModel *model{nullptr}; // nullptr while the copy is out of the scene
|
|
UID uuid;
|
|
// what it takes to make the copy again, filled in when it's taken out of the scene
|
|
std::string serialized;
|
|
std::string name;
|
|
glm::dvec3 position{0.0};
|
|
glm::vec3 rotation{0.0f};
|
|
glm::vec3 scale{1.0f};
|
|
};
|
|
|
|
Action action{Action::Other};
|
|
std::string node_name; // node identifier (basic_node::name())
|
|
// direct pointer to node when available; used for in-memory undo/redo lookup
|
|
scene::basic_node *node_ptr{nullptr};
|
|
std::string serialized; // full text for recreate (used for Add/Delete)
|
|
glm::dvec3 position{0.0, 0.0, 0.0};
|
|
glm::vec3 rotation{0.0f, 0.0f, 0.0f};
|
|
glm::vec3 scale{1.0f, 1.0f, 1.0f};
|
|
UID uuid; // node UUID for reference, used as fallback lookup for deleted/recreated nodes
|
|
scene::layer_handle layer{null_handle}; // scenery layer of the node, so a recreated node returns to it
|
|
scene::instance_handle instance{0}; // include of a scenery template which was placed or removed, instead of a node
|
|
std::vector<scene::instance_handle> instances; // includes placed or removed together
|
|
std::vector<std::pair<scene::instance_handle, std::string>> directives; // includes changed together, with the directives to go back to
|
|
std::vector<std::pair<sweep_node *, sweep_node::state>> sweeps; // models along curves changed, with the definitions to go back to
|
|
std::vector<sweep_node *> sweeps_toggled; // models along curves made or removed: undo flips whether they're there
|
|
std::vector<std::pair<TTrack *, editor_track::state>> tracks;
|
|
std::vector<TTrack *> created;
|
|
std::vector<TTrack *> removed;
|
|
editor_road::record roads; // what a change of the roads comes to
|
|
std::vector<infra::object_state> infra; // objects which followed the paths
|
|
bool profiles{false}; // the stored grade line designs changed too, these were the ones before
|
|
std::vector<stored_profile> profile_library;
|
|
std::optional<std::vector<alignment_store::record>> alignments; // the kept horizontal alignments changed too, these were the ones before
|
|
std::optional<std::vector<switch_store::record>> switch_records; // the kept switches changed too, these were the ones before
|
|
std::optional<srk_hand_joints> hand_joints; // the joints of a station put by hand changed too, these were the ones before
|
|
std::optional<kilometrage::state> kilometrage; // the kilometrage before the change (Action::Kilometrage)
|
|
std::vector<array_copy> copies; // models an array added to the one it was made of
|
|
bool joined{false}; // undone and redone together with the change before it
|
|
std::shared_ptr<terrain_streamer::change const> terrain; // the heightmap terrain from before the change (Action::Terrain)
|
|
std::uint64_t serial{next_serial()}; // of each step made, for the revision of the history
|
|
static std::uint64_t next_serial()
|
|
{
|
|
static std::uint64_t counter{0};
|
|
return ++counter;
|
|
}
|
|
};
|
|
void push_snapshot(scene::basic_node *node, EditorSnapshot::Action Action = EditorSnapshot::Action::Move, std::string const &Serialized = std::string());
|
|
|
|
std::vector<EditorSnapshot> m_history; // history of changes to nodes, used for undo functionality
|
|
std::vector<EditorSnapshot> g_redo;
|
|
int m_track_edits{0};
|
|
// methods
|
|
void update_camera(double const Deltatime);
|
|
// the camera onto the track under the cursor, or the nearest one, to ride along it
|
|
void ride_enter();
|
|
// the way the camera looks, in the plan
|
|
glm::dvec3 camera_look() const;
|
|
|
|
editor_ui *ui() const;
|
|
void redo_last();
|
|
// a single step of the history, see undo_last()
|
|
void undo_one();
|
|
void drop_step(std::size_t const Step);
|
|
std::string refused(std::string Text);
|
|
void redo_one();
|
|
// the changes of the heightmap terrain since the last step become a step of the history: a stroke of the brush,
|
|
// or what a frame did; the next change is recorded from now on
|
|
void terrain_history_step();
|
|
// puts the terrain back as the step recorded it, the step left with the state it replaced
|
|
void restore_terrain(EditorSnapshot &Snapshot);
|
|
// swaps the kilometrage with the one the snapshot keeps
|
|
void restore_kilometrage(EditorSnapshot &Snapshot);
|
|
bool m_history_busy{false}; // undo or redo under way
|
|
void handle_brush_mouse_hold(int Action, int Button);
|
|
void apply_rotation_for_new_node(scene::basic_node *node, int rotation_mode, float fixed_rotation_value);
|
|
// members
|
|
state_backup m_statebackup; // helper, cached variables to be restored on mode exit
|
|
editormode_input m_input;
|
|
static TCamera Camera;
|
|
|
|
// focus (smooth camera fly-to) state
|
|
static bool m_focus_active;
|
|
glm::dvec3 m_focus_start_pos{0.0,0.0,0.0};
|
|
glm::dvec3 m_focus_target_pos{0.0,0.0,0.0};
|
|
glm::vec3 m_focus_start_angle{0.0f}; // camera pitch/yaw/roll at focus start
|
|
glm::vec3 m_focus_target_angle{0.0f}; // camera pitch/yaw/roll facing the focused object
|
|
double m_focus_time{0.0};
|
|
double m_focus_duration{0.6};
|
|
// the last place and angles of the camera which were numbers: a camera gone to no finite place goes back there
|
|
glm::dvec3 m_camera_finite_pos{0.0, 0.0, 0.0};
|
|
glm::vec3 m_camera_finite_angle{0.0f};
|
|
bool m_camera_finite{false};
|
|
|
|
double fTime50Hz{0.0}; // bufor czasu dla komunikacji z PoKeys
|
|
scene::basic_editor m_editor;
|
|
scene::basic_node *m_node{nullptr}; // currently selected scene node
|
|
scene::instance_handle m_instance{0}; // currently selected include of a scenery template; these are handled as a whole
|
|
include_selection m_include; // parameters of the selected include, changed with the gizmo and in the node properties
|
|
bool m_include_gesture{false}; // a change of the selected include is under way, and has its undo snapshot already
|
|
std::vector<std::pair<TAnimModel *, int>> m_retired; // models replaced after changes of includes, with the frames left until they're destroyed
|
|
bool m_takesnapshot{true}; // helper, hints whether snapshot of selected node(s) should be taken before modification
|
|
bool m_dragging = false;
|
|
glm::dvec3 oldPos; // world position of the last brush placement
|
|
bool m_brush_has_last{false}; // false at the start of a brush stroke, so the first placement ignores spacing
|
|
bool m_draw_cursor{false}; // the cursor drawn into the picture (View menu), on only while the editor is
|
|
bool mouseHold{false};
|
|
float kMaxPlacementDistance = 200.0f;
|
|
static bool m_change_history;
|
|
static bool m_settings_open;
|
|
|
|
double m_ortho_pitch{0.0};
|
|
bool m_ortho_pan{false};
|
|
glm::dvec2 m_ortho_pan_cursor{0.0};
|
|
double m_pan_metres{0.0}; // of the ground to a pixel, held by the panning in the perspective view
|
|
void ortho_pan_to(double const Horizontal, double const Vertical);
|
|
void ortho_pan_stop();
|
|
// camera fly-mode (right mouse button held); used to flush motion when it's released
|
|
command_relay m_camera_relay;
|
|
bool m_camera_flying{false};
|
|
|
|
// UI/history settings
|
|
int m_max_history_size{200};
|
|
int m_selected_history_idx{-1};
|
|
glm::dvec3 clamp_mouse_offset_to_max(const glm::dvec3 &offset);
|
|
// the ground under a point the cursor landed on, for things which are to stand on the ground
|
|
glm::dvec3 placement_on_ground(glm::dvec3 Location) override;
|
|
// the ground under a point, the point itself with none there
|
|
glm::dvec3 ground_at(glm::dvec3 Location) const;
|
|
// puts every instance of the model the selected node shows on the ground under it
|
|
void drop_model_instances();
|
|
void render_object_menu();
|
|
// undo, redo and what can be done with the selection, with their keys
|
|
void render_edit_menu();
|
|
// the list of the keyboard shortcuts, opened from the help menu or by F1
|
|
void render_help_menu();
|
|
void render_shortcuts_window();
|
|
bool m_shortcuts_open{false};
|
|
using first_step = editor_first_step;
|
|
// the tutorial: a window of lessons, each with a clip or a sketch, the mouse and the keys it teaches and the steps to try
|
|
struct tutorial_lesson;
|
|
static std::vector<tutorial_lesson> const &tutorial_lessons();
|
|
// a lesson is done once all its steps are
|
|
bool tutorial_done(tutorial_lesson const &Lesson) const;
|
|
void render_first_steps();
|
|
// the steps reached by what the editor is doing now
|
|
void note_first_steps();
|
|
// the lesson of the tool in use: the first of its lessons not done yet, or none
|
|
char const *tutorial_of_tool();
|
|
// the lesson the tool in use or a button of a panel asks for opened, and the clip of the lesson open loaded
|
|
void follow_tutorial();
|
|
void render_tutorial_media(tutorial_lesson const &Lesson, float const Width);
|
|
void render_tutorial_goals(tutorial_lesson const &Lesson);
|
|
// the button under a lesson, opening the tool it's about or switching the view
|
|
void render_tutorial_trial(tutorial_lesson const &Lesson);
|
|
// the buttons to the lesson before and after, and a dot for each lesson, green when it's done
|
|
void render_tutorial_pages();
|
|
void first_step_done(first_step const Step) override;
|
|
void open_kilometrage() override;
|
|
bool m_first_steps_open{false};
|
|
std::array<bool, static_cast<std::size_t>(first_step::count)> m_first_steps_done{};
|
|
int m_tutorial_page{0};
|
|
char const *m_tutorial_goto{nullptr}; // the lesson of this title opened by a button of a panel
|
|
std::string m_tutorial_followed; // the lesson the tool in use asked for last: it's opened when that changes
|
|
double m_tutorial_since{0.0};
|
|
editor_clips::clip m_tutorial_clip;
|
|
// deletes what's selected: a road piece or point, a signal, an include of a scenery template, a model, tracks (Del)
|
|
void delete_selected();
|
|
void delete_model(TAnimModel *Model, bool const Joined);
|
|
|
|
// more models selected at once, in the surroundings: m_node is the one the gizmo is on, the others are in m_selection.
|
|
// Shift+LMB adds a model or takes it out; a model of a group stands for the whole group
|
|
std::vector<scene::basic_node *> m_selection;
|
|
std::vector<scene::basic_node *> selected_nodes() const; // m_node first
|
|
std::vector<scene::basic_node *> selection_with_groups() const; // and the other models of their groups
|
|
void select_node(scene::basic_node *Node, bool const Additive);
|
|
void draw_selection_overlay();
|
|
// the other models of the selection follow m_node moved or turned by the gizmo
|
|
void selection_snapshots(EditorSnapshot::Action const Action);
|
|
void selection_follow(glm::dvec3 const &Moved, glm::vec3 const &Turned, glm::dvec3 const &Pivot);
|
|
// clipboard (Ctrl+C, Ctrl+V): definitions of the models, placed around the cursor as they were around the selected one
|
|
struct clipboard_entry
|
|
{
|
|
std::string definition;
|
|
glm::dvec3 offset{0.0};
|
|
glm::vec3 angles{0.0f};
|
|
glm::vec3 scale{1.0f};
|
|
int group{-1}; // models copied with their group are grouped again, each group anew
|
|
};
|
|
std::vector<clipboard_entry> m_clipboard;
|
|
void copy_selection();
|
|
void paste_clipboard(glm::dvec3 const &Location);
|
|
glm::dvec3 cursor_ground(); // the point of the ground under the cursor
|
|
// groups (Ctrl+G, Ctrl+Shift+G), written to the scenery as group ... endgroup
|
|
void group_selection();
|
|
void ungroup_selection();
|
|
void drop_selection_to_ground();
|
|
// menu at the cursor, Ctrl+RMB
|
|
bool m_contextopen{false};
|
|
glm::dvec3 m_contextpoint{0.0};
|
|
void render_context_menu();
|
|
|
|
// focus camera smoothly on specified node
|
|
void start_focus(scene::basic_node *node, double duration = 0.6);
|
|
|
|
// drops the node straight down onto the nearest surface below (terrain or another object). its group goes along with it,
|
|
// unless Alone: then the node goes by itself. Joined: undone together with the change before
|
|
void snap_to_ground(scene::basic_node *node, bool const Alone = false, bool const Joined = false);
|
|
|
|
// the heightmap terrain of the scenery (terrain/<name>/): chunks, sculpting, painting, water
|
|
void render_terrain_ui();
|
|
// the terrain as a field of work of its own: the terrain tools and the orthophoto in the tool options window
|
|
void render_terrain_tool_options();
|
|
// opens or leaves the terrain; leaving it puts the terrain tools away, so the mouse doesn't stay with them
|
|
void terrain_workspace(bool const Open);
|
|
// opens the heightmap terrain of the scenery for editing, named after the scenery, if the scenery has none yet. returns: true if it's open
|
|
bool ensure_terrain();
|
|
// adds chunks around the camera, Count along a side, at the height of the ground under each grid point where there's any
|
|
void add_chunks_around(int const Count);
|
|
// adds a chunk of the terrain shaped as the ground under it; where there's no ground, carried on level with the nearest point
|
|
// of it, or at the base height. returns: false if there's a chunk already
|
|
bool add_chunk_from_ground(heightmap::chunk_key const &Key, float const Spacing, std::uint16_t const Layer = 0);
|
|
|
|
// the terrain from the digital terrain model of GUGiK (editormodenmt.cpp)
|
|
using nmt_place = ::nmt_place;
|
|
struct nmt_state
|
|
{
|
|
double offset{0.0}; // added to the heights of the model, so they meet the tracks of the scenery
|
|
bool fitted{false};
|
|
bool fitting{false}; // waiting for the model under the places of the tracks the offset is worked out from
|
|
std::vector<nmt_place> fit;
|
|
double spread{0.0}; // how much the tracks differ from the model about the offset, m
|
|
std::size_t samples{0};
|
|
double band{300.0}; // m from the tracks the chunks made along them reach
|
|
bool shape{true}; // the formation and the slopes of the tracks as modifiers of the terrain
|
|
bool grow{true}; // while a track is laid, the terrain is made around the cursor where there's none
|
|
bool laying{false}; // the tracks committed are being laid: they leave the terrain as it is
|
|
bool follow{true}; // a track with its formation edited takes it along, the formation led anew
|
|
bool grown{false}; // the chunks waiting were all asked for by growing: the formations aren't made anew after them
|
|
bool reshape{false}; // the formations of the tracks laid anew once the chunks waiting are made, as the tracks are put onto the terrain
|
|
bool unfitted{false}; // the tracks put onto the terrain are only the ones whose grade line isn't fitted yet
|
|
bool redo_hand{false}; // all anew takes the grade lines edited by hand too
|
|
std::unordered_set<TTrack const *> stayed; // the tracks this putting onto the terrain leaves as they are
|
|
double grow_time{-10.0};
|
|
double slope{1.5};
|
|
double reach{60.0};
|
|
std::vector<heightmap::chunk_key> pending; // chunks to make once their model is in
|
|
// of the chunks waiting, those there already with flat ground, made without the model: the model fills their ground
|
|
std::set<heightmap::chunk_key> refill;
|
|
std::set<heightmap::chunk_key> given_up; // chunks the growing gave up, next to terrain not from the model: not asked for again
|
|
std::size_t made{0};
|
|
std::size_t empty{0}; // chunks not made: the model has no data there
|
|
std::size_t foreign{0}; // chunks not made ahead: the terrain beside isn't of the model
|
|
std::optional<double> ahead; // how much the terrain made ahead lies over the model
|
|
std::set<TTrack *> changed; // tracks whose formations are to follow them
|
|
std::set<std::string> gone; // names of the tracks removed, whose formations go with them
|
|
double changed_time{0.0};
|
|
bool restoring{false}; // the history is taken back or forward: the terrain comes back with it
|
|
std::size_t shaped{0};
|
|
std::string status;
|
|
std::string error;
|
|
bool common{true}; // the tracks nearly parallel under 5.1 m apart lie on one grade line
|
|
static int constexpr grade_line_own{-1};
|
|
static int constexpr grade_line_steep{-2};
|
|
static int constexpr grade_line_off{-3}; // taken off a grade line by hand, stays on its own when the lines are worked out again
|
|
static int constexpr grade_line_off_number{-10}; // this and below: taken off the grade line of this number less this
|
|
std::map<std::string, int> grade_lines; // of each track the number of the grade line it shares, or one of those above
|
|
std::set<std::string> grade_lines_hand; // the tracks put on their grade line by hand: they stay on it when the lines are worked out again
|
|
bool grade_lines_loaded{false};
|
|
bool grade_lines_dirty{false}; // the edits of the tracks carried their lines on: stored once, with the next frame
|
|
std::unordered_map<TTrack const *, std::string> grade_line_keys; // of the tracks changed, the key each had last, to carry its line on to the next
|
|
std::vector<std::pair<std::string, segment_data>> grade_line_replaced; // the first paths of the tracks of a line changed since the last frame: a new track on one takes its line
|
|
std::unordered_set<TTrack const *> on_hump; // the tracks of the humps fitted to the model: no grade line shared levels them
|
|
std::size_t grade_lines_changes{0};
|
|
std::string explain; // a track whose run the next sharing of the grade lines tells of in the log, for a selftest
|
|
struct surface_place
|
|
{
|
|
TTrack const *track;
|
|
int path;
|
|
double share;
|
|
int surface;
|
|
};
|
|
std::vector<surface_place> surface_places; // what lies on the surface of each group on common timbers
|
|
bool camera_check{false}; // chunks were made: the 3d camera may be under them now
|
|
std::vector<std::string> buried; // the tracks just laid, when a part of them is hidden in the ground
|
|
double buried_length{0.0}; // m of them hidden
|
|
// the tracks of a scenery built at any height put onto the terrain model: the model offset to meet the scenery, then the grade
|
|
// line of each line of tracks fitted to the model, the longest first, then the terrain made along them
|
|
enum class automatic
|
|
{
|
|
idle,
|
|
fetching, // the model under the tracks
|
|
fitting // the grade lines, a few each frame
|
|
};
|
|
automatic stage{automatic::idle};
|
|
std::vector<nmt_place> probes; // places of the tracks whose model is waited for
|
|
std::size_t probes_kept{0}; // the last of the probes, on tracks fitted already: they tell the offset the model had
|
|
std::size_t tracks{0}; // rail tracks when the grade lines began, and the paths the grade lines split off since
|
|
std::size_t split{0};
|
|
std::vector<TTrack *> left; // tracks whose grade line is still to be fitted
|
|
std::vector<TTrack *> done; // tracks of the lines fitted already: the lines fitted later end on them and don't change them
|
|
// the rail tops of the lines fitted already, in squares of the plan: the tracks of a station lie in one plane, a line laid
|
|
// near them takes their height for its ground too, the more closely the nearer it is, and a line crossing one of them
|
|
// on its level its height on the crossing
|
|
struct laid_point
|
|
{
|
|
glm::dvec3 position{0.0};
|
|
glm::dvec2 direction{0.0, 1.0};
|
|
double grade{0.0};
|
|
double was{0.0}; // the height before the line was fitted
|
|
double rails{0.0}; // the height of the rails of the track
|
|
TTrack const *track{nullptr};
|
|
};
|
|
std::map<std::pair<int, int>, std::vector<laid_point>> laid;
|
|
// the points of all the paths as they were laid, for the crossings
|
|
std::map<std::pair<int, int>, std::vector<laid_point>> paths;
|
|
// ends which meet in the plan unlinked, laid apart in height, that the joining of the ends couldn't join as neither of
|
|
// them can be changed alone, as of two switches: each with the other one, which a line ending there takes over
|
|
std::map<std::tuple<TTrack const *, int, bool>, std::tuple<TTrack *, int, bool>> loose;
|
|
// the points of the lines over a bridge or a viaduct, the model falling away under them: no formation is laid there
|
|
std::map<std::pair<int, int>, std::vector<glm::dvec3>> bridged;
|
|
// a turntable lies level in its pit, which the model has, at the height of the tracks running up to it: it isn't put onto
|
|
// the model, and a line ending on its rim ends there level at its height, turning to the model away from it
|
|
struct turntable
|
|
{
|
|
TTrack *table{nullptr};
|
|
glm::dvec3 centre{0.0}; // at the height of its rails
|
|
double rim{0.0}; // m from the centre
|
|
std::vector<std::tuple<TTrack *, int, bool>> ends; // of the paths running up to it: track, path, at its end
|
|
};
|
|
std::vector<turntable> turntables;
|
|
std::size_t levelled{0}; // turntables moved to the height of their tracks
|
|
std::size_t lines{0}; // grade lines fitted and applied
|
|
std::size_t refused{0}; // grade lines the checks didn't let apply
|
|
std::size_t departures{0}; // grade lines parting from the terrain model by much
|
|
// what the last putting of the tracks onto the terrain found, listed in the panel to be looked at: a line the checks
|
|
// refused, a line parting from the model by much, a path which didn't take its line
|
|
struct finding
|
|
{
|
|
enum class kind
|
|
{
|
|
refused,
|
|
off,
|
|
parted
|
|
};
|
|
kind what{kind::refused};
|
|
TTrack *from{nullptr}; // the ends of the line, for its profile
|
|
TTrack *to{nullptr};
|
|
double length{0.0};
|
|
glm::dvec3 where{0.0}; // the place to look at
|
|
std::string text;
|
|
double size{0.0}; // m the line or the path is off by: of one kind the worst told first
|
|
};
|
|
std::vector<finding> findings;
|
|
bool result{false}; // the putting onto the terrain ended: what it did is told in the panel until the next one
|
|
bool run{false}; // the tracks are being put onto the terrain, the chunks after the grade lines too: the steps told
|
|
std::size_t fetch_most{0}; // the most squares of the model waited for since the loading began, for its progress
|
|
// the terrain made under the tracks as they are: the model drawn to them by the difference found at the places along them,
|
|
// fading out away from them into the offset of the whole scenery
|
|
bool under{false};
|
|
std::vector<glm::dvec3> anchors; // x, z of a place of the tracks, the formation there less the model
|
|
std::map<std::pair<int, int>, std::vector<std::size_t>> anchor_cells; // the anchors in squares of the plan
|
|
bool offered{false}; // the terrain was offered to the scenery begun without it
|
|
bool prompt{false}; // the offer is shown
|
|
bool moving{false}; // the place being picked again
|
|
char place[96]{}; // typed: degrees or PUWG 1992
|
|
int shown{-1}; // the frame the terrain panel showed how far the work got
|
|
};
|
|
editor_nmt m_nmt;
|
|
nmt_state m_nmt_state;
|
|
editor_map m_nmt_map;
|
|
std::vector<nmt_place> nmt_track_places(double const Step) const override;
|
|
void nmt_locate() override;
|
|
void nmt_fit();
|
|
void nmt_finish_fit();
|
|
// the terrain under the tracks, the tracks left as they are: the model drawn to each of them, its relief kept
|
|
void nmt_under_start();
|
|
void nmt_under_anchors();
|
|
// added to the height of the model at the place: the offset of the scenery, drawn to the tracks near them
|
|
double nmt_offset_at(double const X, double const Z) const;
|
|
std::vector<heightmap::chunk_key> nmt_keys_around() const;
|
|
std::vector<heightmap::chunk_key> nmt_keys_along_tracks() const;
|
|
// only the chunks there are none of yet: a chunk there is, made from the model or by hand, edited or not, is never made anew.
|
|
// Reshape: the formations of the tracks laid anew as the tracks lie now, as when they moved
|
|
void nmt_make(std::vector<heightmap::chunk_key> const &Keys, bool const Reshape = false);
|
|
enum class nmt_chunk
|
|
{
|
|
waiting, // for its squares of the model
|
|
made,
|
|
empty // the model has no data there
|
|
};
|
|
// Offset: the heights of the model go up or down by it in the whole chunk, in place of the offsets of the fit
|
|
nmt_chunk add_chunk_from_nmt(heightmap::chunk_key const &Key, std::optional<double> const Offset = std::nullopt);
|
|
// a chunk there with its ground level all over, as made where there was no ground and no model: none of the shape of the land
|
|
bool nmt_flat_chunk(heightmap::chunk_key const &Key) const;
|
|
// how much the terrain lies over the model at the points: none where there's too little terrain at them, nor where it
|
|
// doesn't follow the model (Foreign), as one made by hand
|
|
std::optional<double> nmt_terrain_offset(std::vector<glm::dvec2> const &Points, bool &Foreign) const;
|
|
// the same along the edges the chunk shares with the chunks beside it in memory
|
|
std::optional<double> nmt_seam_offset(heightmap::chunk_key const &Key, bool &Foreign) const;
|
|
// the offset a chunk made from the model where there's no terrain gets: of the terrain made from the model beside it, empty
|
|
// (the offset of the scenery) beside terrain made by hand or none
|
|
std::optional<double> nmt_chunk_offset(heightmap::chunk_key const &Key) const;
|
|
// the terrain beside the formation of the track is the one made from the model; Waiting: its squares of the model aren't in yet
|
|
// the tracks changed by hand are told to the terrain: their formations laid anew, of the tracks removed taken away, a
|
|
// track laid onto the terrain of the model given its own, once the mouse lets go; in the step of the history of the change
|
|
void nmt_track_changed(std::vector<TTrack *> const &Tracks);
|
|
void nmt_track_gone(TTrack const &Track);
|
|
void nmt_follow_tracks();
|
|
// the height the ground will have where the terrain is made ahead of the track laid and isn't there yet
|
|
bool nmt_ahead(double const X, double const Z, double &Height) const;
|
|
// the same, else the height of the model with the offset of the scenery where its square is in: the ground where there's no
|
|
// terrain made yet, as under the base map of the top view
|
|
bool nmt_ground(double const X, double const Z, double &Height) const;
|
|
// the squares of the model under the rectangle are in, none of them waiting to be asked for again
|
|
bool nmt_ready(glm::dvec2 const &Min, glm::dvec2 const &Max);
|
|
// Only: the paths of these tracks are shaped anew, the modifiers of those removed taken away; null: all of them. the number
|
|
// of the modifiers laid
|
|
std::size_t nmt_shape_tracks(std::vector<TTrack *> const *Only = nullptr);
|
|
void nmt_update();
|
|
// the terrain of the scenery made from the model around the camera within the download area, a chunk at a time while nothing
|
|
// else is done with the model and the frames are quick: edited chunks wait in memory to be saved, so not the whole area at once
|
|
void nmt_area_terrain();
|
|
void nmt_grow();
|
|
void render_nmt_ui();
|
|
// where the scenery lies: the map to click on, the place typed; true once it's placed
|
|
bool render_nmt_place(bool const Moving, bool const Button);
|
|
// the work under way: what's left of it and the button to stop it; Compact: one line, for the 3d view
|
|
void render_nmt_progress(bool const Compact);
|
|
// the formations of the tracks led into the terrain, down or up to it, or taken out of it; one step of the history each
|
|
void nmt_pull_terrain(std::vector<TTrack *> const &Tracks);
|
|
void nmt_restore_terrain(std::vector<TTrack *> const &Tracks);
|
|
// the terrain of the selected tracks in the panel of the tracks
|
|
void render_track_terrain(std::vector<TTrack *> const &Tracks);
|
|
// all the tracks of the scenery onto the terrain model, or it under them: step 2 of the terrain model (Terrain_panel), and in
|
|
// the panel of the tracks
|
|
void render_nmt_all_tracks(bool const Terrain_panel);
|
|
// what the last putting of the tracks onto the terrain did, and the places it found to be looked at, each to be shown
|
|
void render_nmt_result();
|
|
// a line from From to To being put onto the terrain kept to be looked at: the place of it to show and what's wrong there
|
|
void nmt_note(nmt_state::finding::kind const What, TTrack *From, TTrack *To, double const Length, glm::dvec3 const &Where, std::string Text, double const Size = 0.0);
|
|
// the place found shown in the 3d view with the track there selected; Profile: the profile of its line opened too
|
|
void nmt_show(nmt_state::finding const &Finding, bool const Profile);
|
|
// the chunks waiting for the terrain model and the tiles of the imagery asked for outlined where they will be, so it's seen
|
|
// what's on its way
|
|
void draw_nmt_pending() const;
|
|
// the download area: a polygon drawn on the map, the boundary of what the orthophoto and the terrain model download in the
|
|
// background, none of them asking for anything outside it (application/editormodenmt.cpp)
|
|
void area_start();
|
|
// Keep: the area drawn taken, else the one before stays
|
|
void area_finish(bool const Keep);
|
|
// a press of the left button while drawing: a point added, or the one under the cursor taken to drag, Shift: removed
|
|
void area_click(bool const Shift);
|
|
void area_update();
|
|
// a point of the area (x, z) where it's drawn: over the map of the top view, on the ground in the 3d view
|
|
glm::dvec3 area_point(glm::dvec2 const &Point) const;
|
|
void draw_download_area() const;
|
|
void render_download_area_ui(editor_orthophoto::statistics const &Stats);
|
|
// the download area a square of the side, km, around the camera
|
|
void area_square(int const Side);
|
|
// the chunk of the terrain (x, z) touches the area, or there's none
|
|
bool in_download_area(glm::dvec2 const &Low, glm::dvec2 const &High) const;
|
|
// over the 3d view while the terrain panel isn't seen
|
|
void render_nmt_banner();
|
|
// the grade lines fitted, the tracks nearly parallel under 5.1 m apart brought onto one, a track going away from them fading back onto its own
|
|
void nmt_share_grades();
|
|
void grade_lines_load();
|
|
void grade_lines_store();
|
|
bool on_route_grade_line(TTrack const &Track);
|
|
std::vector<TTrack *> const &grade_line_beside();
|
|
std::size_t grade_line_follow(std::vector<editor_track::route_sample> const &Before);
|
|
void grade_line_take_off(bool const Off);
|
|
// the grade line the route shares, by most of its paths; -1 when it shares none
|
|
int route_grade_line();
|
|
// the plain tracks from switch to switch the track is one of, a switch by itself; Alone: the track only
|
|
static std::vector<TTrack *> grade_line_run(TTrack &Track, bool const Alone);
|
|
// the run of the track clicked onto the grade line of the route by hand, or off it if it's on it; a route sharing none makes one with it
|
|
void grade_line_pick(TTrack &Track, bool const Alone);
|
|
// all the tracks of the grade line, wherever they are, for the view while they're picked
|
|
std::vector<TTrack const *> const &grade_line_members(int const Number);
|
|
void draw_grade_line_pick();
|
|
// a piece split off a track lies on the grade line the track does
|
|
void grade_line_split(TTrack const &Original, TTrack const &Created);
|
|
// a track changed keeps its grade line under the key it has after it; a new one between two tracks of a line, a switch put into one, lies on it
|
|
void grade_line_captured(TTrack const &Track);
|
|
void grade_lines_committed(std::vector<TTrack *> const &Tracks);
|
|
void grade_line_renamed(TTrack const &Track, std::string const &Old);
|
|
void render_profile_grade_line();
|
|
// the tracks laid since the step of the history hidden in the ground, told over the 3d view with the way to fit the ground to them
|
|
void nmt_check_buried(std::size_t const From);
|
|
void render_nmt_buried();
|
|
// what to do first, in the middle of the view of a scenery with no tracks nor terrain
|
|
void render_empty_scenery_hint();
|
|
// the camera outside the download area: no photos there, told at the bottom of the view with the way to the area
|
|
void render_outside_area_hint();
|
|
// the 3d camera under the ground, as after the view from above or the terrain model made under it, lifted over it
|
|
void camera_above_ground();
|
|
bool nmt_busy() const;
|
|
// the terrain made so far stays, what's waiting is dropped, the grade lines not fitted yet are left
|
|
void nmt_stop();
|
|
// a scenery begun from nothing, with no tracks nor terrain, is asked as the first track is laid whether it wants the terrain
|
|
void nmt_offer();
|
|
void render_nmt_prompt();
|
|
// the place picked in the terrain window: the terrain model and the orthophoto take it
|
|
void nmt_place_scenery(glm::dvec2 const &Point);
|
|
void nmt_accept_offer();
|
|
// the whole scenery: tracks, includes and models, moved up or down as one undo step
|
|
std::size_t nmt_join_ends();
|
|
// the turntables as they lie, each with the ends of the tracks running up to it on its rim
|
|
std::vector<nmt_state::turntable> nmt_turntables() const;
|
|
// each turntable level at the height of the tracks running up to it, its include with it, before the grade lines are fitted:
|
|
// at the height of the ones fitted already, else of the terrain model beside its rim; the number of them moved
|
|
std::size_t nmt_level_turntables();
|
|
// Unfitted: only the tracks whose grade line isn't fitted yet, the scenery left at its height
|
|
void nmt_auto_start(bool const Unfitted = false);
|
|
void nmt_auto_step();
|
|
// the grade line of the line of tracks through the track fitted to the terrain model and applied; false if it couldn't be.
|
|
// The line runs over the tracks not Fitted, the ones fitted stay as they are and the line meets them. Where the model falls
|
|
// away under the line by the abutments the tracks go over on a bridge; Laid: the tracks just laid, the formation fills it and
|
|
// they are cut only where they can't follow the line otherwise
|
|
bool nmt_fit_line(TTrack &Track, std::function<bool(TTrack const *)> const &Fitted, bool const Laid);
|
|
// the tracks laid in one go since the history step From put onto the terrain model as one line, as the tracks go onto the
|
|
// terrain: the track ending at End then the one the laying goes on from
|
|
bool nmt_fit_laid(std::size_t const From, glm::dvec3 const End);
|
|
// the tracks laid one after another on one straight or one arc, cut by the grade lines fitted before, made one again
|
|
void nmt_merge_laid(std::unordered_set<TTrack const *> &Laid);
|
|
// the points of the paths of the track about a metre apart, in squares of the plan
|
|
static void nmt_sample_paths(TTrack const &Track, std::map<std::pair<int, int>, std::vector<nmt_state::laid_point>> &Points);
|
|
// the tool of the terrain the left mouse button works
|
|
enum class terrain_tool
|
|
{
|
|
none, // picks the models, as in the surroundings
|
|
chunks, // adds a chunk, Shift: removes it
|
|
sculpt, // raises the ground, Shift: lowers it
|
|
smooth,
|
|
level, // leads the ground to the target height, Ctrl: picks the target height under the cursor
|
|
paint, // paints the chosen material, Shift: the first material of the palette
|
|
spacing, // selects chunks (Ctrl: adds or takes away one), whose point spacing is then converted
|
|
water, // outlines a body of water
|
|
restore, // takes the touch-ups over the modifiers back
|
|
fill // outlines an area filled with a material
|
|
};
|
|
terrain_tool m_terrain_tool{terrain_tool::none};
|
|
bool terrain_brush() const
|
|
{
|
|
return m_terrain_tool == terrain_tool::sculpt || m_terrain_tool == terrain_tool::smooth || m_terrain_tool == terrain_tool::level || m_terrain_tool == terrain_tool::paint ||
|
|
m_terrain_tool == terrain_tool::restore;
|
|
}
|
|
// the point of the ground of the terrain under the cursor, found along the ray through the cursor, so it's found also over
|
|
// a hole and behind the grass. returns: false if the ray meets no terrain
|
|
bool terrain_cursor(glm::dvec3 &World) const;
|
|
// the point of the ground under the cursor in this frame, for the points put on the ground (outlines, areas, brushes): along the ray
|
|
// through the cursor to the terrain; the depth read back (a frame late, and stopped by the models over the ground) only where
|
|
// there's none. false: nothing under the cursor
|
|
bool cursor_on_ground(glm::dvec3 &World);
|
|
// converts the point spacing of the selected chunks to m_terrain_convert_spacing
|
|
void convert_selected_chunks();
|
|
// the chunks selected with the spacing tool taken out of the terrain, in one step of the history
|
|
void remove_selected_chunks();
|
|
// takes the height of whatever is under the cursor (terrain, track, model) for the target of the level brush. returns: false if there's nothing
|
|
bool pick_terrain_target();
|
|
bool terrain_clicking() const { return m_terrain_tool == terrain_tool::chunks || m_terrain_tool == terrain_tool::spacing || m_terrain_tool == terrain_tool::water || m_terrain_tool == terrain_tool::fill; }
|
|
// fills the outlined area with the material of the chosen palette entry, turned by m_paint_rotation
|
|
void fill_terrain_area();
|
|
// the brush, the hovered chunk and the outlines of water drawn over the viewport
|
|
void draw_terrain_overlay();
|
|
// forgets what's known about the ground, after the terrain changed
|
|
void forget_ground();
|
|
// the ground gathered where the terrain changed in the rectangle (x, z) gathered again when asked for, the rest kept
|
|
void forget_ground_in(glm::dvec2 const &Min, glm::dvec2 const &Max);
|
|
// conversion of the ground of the terrain files of the scenery (terrain directive, .txtf/.btf) to heightmap terrain
|
|
struct ground_conversion
|
|
{
|
|
struct source
|
|
{
|
|
std::string file; // as the terrain directive names it
|
|
std::uint16_t reference{0}; // see scene::terrain_file::reference_of()
|
|
bool text{false}; // read from the text file, rather than the binary one
|
|
bool good{false};
|
|
bool chosen{true};
|
|
std::string message;
|
|
std::size_t first{0}, count{0}; // its triangles
|
|
};
|
|
bool open{false};
|
|
std::vector<source> files;
|
|
std::vector<std::array<glm::dvec3, 3>> triangles;
|
|
std::vector<std::uint16_t> materials; // of the triangles: index of the name
|
|
std::vector<std::string> names; // of the materials
|
|
std::set<std::size_t> chosen; // materials to convert
|
|
std::string status;
|
|
} m_ground_conversion;
|
|
// reads the triangles of the terrain files of the scenery for the conversion
|
|
void load_ground_files();
|
|
// the folder of the textures as a browser, in the window of the node bank while the terrain is edited: the textures and the
|
|
// materials can be dragged onto the fields which take a material
|
|
struct texture_browser
|
|
{
|
|
struct item
|
|
{
|
|
std::string name; // as the materials are named: relative to the folder of the textures, without the extension
|
|
std::string label; // the file, without the folder
|
|
bool material{false}; // there's a .mat file of the name
|
|
};
|
|
std::string folder; // relative to the folder of the textures, empty or with a trailing slash
|
|
std::vector<std::string> folders; // under the current one
|
|
std::vector<item> items;
|
|
bool listed{false};
|
|
char filter[64]{};
|
|
float size{96.f}; // of the images, pixels
|
|
std::string selected;
|
|
struct thumbnail
|
|
{
|
|
int texture{0}; // 0: none
|
|
int material{0}; // the material the texture is the first of, 0: a texture alone
|
|
double shown{0.0}; // when it was last asked for, ImGui time
|
|
};
|
|
std::map<std::string, thumbnail> thumbnails; // texture shown for the item of the name
|
|
bool refresh{false}; // all the images to be let go of and read again
|
|
int loads{0}; // textures read in the frame, a few at most so the browser doesn't stall the editor
|
|
int loadsframe{-1};
|
|
} m_textures;
|
|
void render_texture_browser();
|
|
// texture of the image of the item of the browser, 0 while there's none
|
|
std::uint64_t texture_thumbnail(texture_browser::item const &Item);
|
|
// the textures of the images out of sight for a while taken out of the memory: a picker of thousands of them scrolled
|
|
// through would keep them all, full size, until the memory ran out
|
|
void thumbnails_trim();
|
|
// takes a material dragged from the texture browser onto the item drawn last. returns: true if one was dropped, its name in Name
|
|
static bool material_drop(std::string &Name);
|
|
// the same, for a text field
|
|
static bool material_drop(char *Buffer, std::size_t Size);
|
|
// replaces the chosen triangles of the chosen terrain files with chunks of heightmap terrain of their shape, painted with
|
|
// their materials; the files lose them on save. returns: summary for the user
|
|
std::string convert_ground();
|
|
void render_ground_conversion();
|
|
// handles a click of the chunk, spacing and water tools (Shift: the other way round)
|
|
void handle_terrain_click(bool const Shift);
|
|
// writes the changes to the files of scenery opened for editing (Ctrl+S)
|
|
bool save();
|
|
// places include of specified scenery template at the cursor, in the active layer
|
|
void place_include(std::string const &File, int RotationMode, float FixedRotation);
|
|
// undo and redo of placing or removing an include: brings removed include back, or removes it
|
|
void toggle_include(scene::instance_handle Instance);
|
|
// makes specified include the selected one, 0 clears the selection
|
|
void select_include(scene::instance_handle Instance);
|
|
// writes parameter values of the selected include to its directive, and shows the outcome in the scene
|
|
void apply_include();
|
|
// replaces directive of specified include, and the models shown for it
|
|
void set_include_directive(scene::instance_handle Instance, std::string const &Directive);
|
|
// undo and redo of an include snapshot
|
|
void restore_include(EditorSnapshot &Snapshot);
|
|
// undo and redo of the includes placed, removed or changed together
|
|
void restore_includes(EditorSnapshot &Snapshot);
|
|
// gizmo for the selected include, limited to what the parameters of its template can express
|
|
void render_include_gizmo(glm::mat4 const &View, glm::mat4 const &Projection, glm::dvec3 const &Camerapos);
|
|
// exports the scenery in legacy (text) format, with layers hidden in the editor left out of the picture
|
|
void export_scenery();
|
|
// works the brush of the terrain under the cursor while the left mouse button is held
|
|
void handle_terrain_brush(double Deltatime);
|
|
// the chunk of the terrain (if any) covering the given world point
|
|
editor_terrain *terrain_at(double X, double Z);
|
|
// the chunks of the terrain held in memory
|
|
std::vector<editor_terrain *> active_terrains() const;
|
|
// samples the selected model instance's geometry into the chunks of the terrain it covers, then removes it
|
|
void capture_terrain();
|
|
bool m_terrain_open{false}; // the terrain is the field of work, chosen in the toolbar
|
|
float m_terrain_spacing{2.0f}; // point spacing of the chunks made and of the spacing tool
|
|
float m_terrain_baseheight{0.0f}; // height of chunks made where there's no ground
|
|
int m_terrain_add_count{4}; // chunks along a side added around the camera
|
|
float m_terrain_brush_radius{12.0f};
|
|
float m_terrain_brush_strength{4.0f}; // metres per second while held; for the paint, how fast it covers
|
|
// the level brush
|
|
float m_terrain_target{0.0f}; // height the ground is led to
|
|
int m_terrain_level_mode{0}; // 0: up and down, 1: only raises, 2: only lowers
|
|
bool m_terrain_target_from_stroke{false}; // the target is the height where a stroke starts
|
|
bool m_terrain_stroke{false}; // a stroke of the brush is under way
|
|
bool m_terrain_picking{false}; // the next click picks the target height
|
|
int m_terrain_layer{0}; // entry of the palette painted
|
|
char m_terrain_material[128]{"grass"}; // material added to the palette
|
|
float m_terrain_material_size{0.0f}; // metres its textures repeat at, 0: given by the material
|
|
float m_terrain_layer_size{0.0f}; // repeat of the chosen palette entry, while it's dragged
|
|
bool m_terrain_layer_size_dragged{false};
|
|
float m_terrain_layer_rotation{0.0f}; // angle of the chosen palette entry, while it's dragged
|
|
bool m_terrain_layer_rotation_dragged{false};
|
|
std::vector<glm::dvec3> m_water_points; // outline of a body of water being drawn
|
|
float m_water_level{0.0f};
|
|
bool m_water_level_edited{false}; // the level was given by hand, the points clicked don't change it
|
|
char m_water_material[128]{""};
|
|
int m_water_selected{-1};
|
|
char m_water_selected_material[128]{""}; // material of the chosen water, while it's edited
|
|
int m_water_material_of{-1}; // the water whose material is in the field above
|
|
float m_water_selected_size{0.0f}; // metres its texture repeats at, 0: given by the material
|
|
std::set<heightmap::chunk_key> m_terrain_selection; // chunks chosen with the spacing tool
|
|
float m_terrain_convert_spacing{1.0f}; // point spacing the selected chunks are converted to
|
|
bool m_terrain_convert_paint{true}; // chunks converted to 0.5 m get paint samples every 0.5 m too
|
|
std::vector<glm::dvec3> m_paint_outline; // of the area filled with a material
|
|
float m_paint_feather{0.0f}; // metres the filled material blends in over across the outline, 0: sharp
|
|
float m_paint_rotation{0.0f}; // degrees the textures of the filled material are turned by
|
|
float m_water_selected_level{0.0f}; // level of the chosen water, while it's edited
|
|
bool m_water_level_dragged{false};
|
|
std::string m_terrain_status;
|
|
|
|
// the heightmap terrain, shared with the scenery loader so it shows in every mode
|
|
terrain_streamer &m_streamer{EditorTerrain};
|
|
|
|
// geoportal orthophoto layer drawn under the other viewport overlays
|
|
void render_orthophoto_ui();
|
|
void render_map_menu();
|
|
bool m_newscenery_asked{false};
|
|
void render_new_scenery_popup();
|
|
bool restart_for_new_scenery();
|
|
bool restart_editor(std::string const &Scenery);
|
|
bool m_openscenery_asked{false};
|
|
bool m_opened_at_track{false};
|
|
bool m_turntable_included{false};
|
|
bool turntable_controls(std::vector<std::string> &Rootstatements);
|
|
bool m_nose_included{false};
|
|
bool nose_controls(std::vector<std::string> &Rootstatements);
|
|
void starter_trainset(std::vector<std::string> &Trailing);
|
|
std::optional<std::pair<glm::dvec3, glm::vec3>> m_saved_camera;
|
|
char m_openscenery_search[64]{};
|
|
std::vector<std::string> m_openscenery_list;
|
|
std::string m_openscenery_choice;
|
|
void render_open_scenery_popup();
|
|
// the settings of the orthophoto, among the base layers in the layers window: asked to be opened there, the frame they were last
|
|
// drawn open in
|
|
bool m_orthophoto_window{false};
|
|
// the user turned the orthophoto on or off, or the scenery keeps it so: the terrain model made, or the area drawn, leaves it as it
|
|
// is then, it turns it on only where nobody chose
|
|
bool m_orthophoto_chosen{false};
|
|
// the user turns the orthophoto on or off: kept with the editor, for every scenery
|
|
void choose_orthophoto(bool const On);
|
|
int m_orthophoto_frame{-10};
|
|
bool orthophoto_settings_open() const;
|
|
// view menu: the top view, the lanes of the roads, the structure gauge, the environment
|
|
void render_view_menu();
|
|
// View > Camera speed: the speed of the free camera, the Ctrl multiplier, in the top view as fast as it's zoomed; kept in the
|
|
// settings of the editor and handed to the camera
|
|
void render_camera_settings();
|
|
void apply_camera_settings();
|
|
// ~ (Ctrl): the orthophoto of what the camera sees downloaded before the rest, the ones which failed tried again at once
|
|
void orthophoto_hurry();
|
|
// time of day, day of the year, visibility, clouds and air temperature, as the scenery is seen in the editor
|
|
void render_environment_window();
|
|
bool m_environment_open{false};
|
|
// over the 3d view: the tools of the field of work along its left edge, the modes of the gizmo at its top, the axes of the
|
|
// world and the top view in its top right corner
|
|
void render_viewport_overlays();
|
|
// the tools of the field of work, in the order of the toolbar
|
|
void work_area_tools(std::vector<editor_tool_button> &Buttons);
|
|
// the tools of the field of work in the toolbar, as icons with their names
|
|
void render_toolbar_tools();
|
|
// what the row of the toolbar holds, written at its left end: the fields of work, the tools
|
|
static void render_toolbar_caption(char const *Text);
|
|
void render_viewport_gizmo();
|
|
void render_view_axes();
|
|
// the camera looking along an axis of the world (0: x, 1: y, 2: z) from its positive or negative side
|
|
void look_along_axis(int const Axis, bool const Positive);
|
|
// origin of the scenery in PUWG 1992 the scenery file gives in its //$g line, if it does
|
|
bool m_georeference_read{false};
|
|
bool m_georeference{false};
|
|
glm::dvec2 m_georeference_origin{0.0}; // northing, easting
|
|
std::string m_georeference_line;
|
|
void read_georeference();
|
|
void draw_orthophoto();
|
|
void draw_ortho_compass() const;
|
|
// picks up the stored settings and the origin of the current scenery, and the offset of the terrain model the scenery has
|
|
void load_orthophoto_settings();
|
|
void save_orthophoto_settings();
|
|
// the settings of the terrain model changed, kept with the editor, and the offset of the model with the scenery's
|
|
void keep_nmt_settings();
|
|
editor_orthophoto m_orthophoto;
|
|
// the WMS layers of the user's over the orthophoto, the top one first, as the settings of the editor keep them; their tiles are
|
|
// kept in memory only
|
|
std::vector<std::unique_ptr<editor_orthophoto>> m_wms;
|
|
// a WMS layer being added: the address typed, what its capabilities tell, read on a thread of its own, the layers ticked
|
|
struct wms_adding
|
|
{
|
|
std::array<char, 512> url{};
|
|
std::array<char, 64> filter{};
|
|
// the reading is given up: the editor goes. before the reading, so it outlives the future waiting for the reading to end
|
|
std::atomic<bool> closing{false};
|
|
std::future<editor_orthophoto::service_info> reading;
|
|
std::optional<editor_orthophoto::service_info> info;
|
|
std::string service; // the address the capabilities were read of
|
|
std::vector<char> ticked;
|
|
} m_wms_adding;
|
|
// the orthophoto and the WMS layers of the user's at the bottom of the layers window, with their settings
|
|
void render_base_layers();
|
|
void render_wms_adding();
|
|
// the WMS layers as the settings have them, laid out by the origin and on the ground of the orthophoto, around the camera
|
|
void update_wms_layers();
|
|
// the ground the imagery is fitted onto, the same for the orthophoto and the WMS layers
|
|
void ground_sources(editor_orthophoto &Layer);
|
|
std::size_t m_ortho_resident{0}; // chunks of the terrain in memory, as the imagery last heard of them
|
|
std::size_t m_ortho_waiting{0}; // squares of the terrain model asked for and not in yet, the same
|
|
std::string m_orthophoto_scenery; // scenery whose origin is loaded
|
|
std::string m_orthophoto_mark;
|
|
std::vector<std::string> m_orthophoto_area_mark; // the lines of the download area as the scenery keeps them
|
|
// the download area being drawn on the map: its points in the world (x, z), the one dragged
|
|
struct area_drawing
|
|
{
|
|
bool active{false};
|
|
std::vector<glm::dvec2> points;
|
|
int dragged{-1};
|
|
} m_area_drawing;
|
|
std::vector<glm::dvec2> m_nmt_prefetched; // the download area the terrain model was given
|
|
bool m_area_paused{false}; // the download of the area held by the button; out of the editor it's held anyway
|
|
// the terrain made around the camera within the area: the chunks there, nearest first, the next one looked at, when the next one
|
|
// may be made, those made (or left: the model has no data there, or the chunk is outside the region) since the scenery opened
|
|
struct area_terrain
|
|
{
|
|
std::vector<heightmap::chunk_key> keys;
|
|
std::size_t next{0};
|
|
heightmap::chunk_key centre{0, 0};
|
|
bool listed{false};
|
|
double resume{0.0};
|
|
std::size_t made{0};
|
|
std::size_t square_made{0}; // of them, in the square around the camera now
|
|
bool refit{false}; // chunks made since the photos were last laid onto the ground
|
|
double waiting{-1.0}; // since when the next chunk waits for its model; -1: it doesn't
|
|
std::string held{"-"}; // what held it last, as logged; empty: nothing
|
|
double took{0.0}; // s the chunks of the square around the camera took, all and the longest
|
|
double took_most{0.0};
|
|
std::set<heightmap::chunk_key> empty;
|
|
std::optional<bool> run_only; // the selftest turned it on or off for its run, the setting left as it is
|
|
} m_area_terrain;
|
|
int m_area_square{0}; // km, the side of the square around the camera waiting for its yes in place of the area there is
|
|
bool m_outside_area_closed{false}; // the note of the camera outside the area closed; open again once it's back inside
|
|
int m_empty_hint_frame{-10}; // the frame the panel of the empty scenery was last drawn in
|
|
glm::dvec2 m_orthophoto_origin_edit{0.0}; // origin being typed in (northing, easting); applied when editing ends
|
|
|
|
// hierarchy management
|
|
void add_to_hierarchy(scene::basic_node *node);
|
|
void remove_from_hierarchy(scene::basic_node *node);
|
|
void erase_model(TAnimModel *model);
|
|
scene::basic_node* find_in_hierarchy(const std::string &uuid_str);
|
|
scene::basic_node* find_node_by_any(scene::basic_node *node_ptr, const std::string &uuid_str, const std::string &name);
|
|
|
|
// clear history/redo pointers that reference the given node (prevent dangling pointers)
|
|
void nullify_history_pointers(scene::basic_node *node);
|
|
void render_change_history();
|
|
void render_settings();
|
|
|
|
// area fill: scatters models from a package over a polygon outlined in the viewport
|
|
void render_area_fill();
|
|
void draw_area_fill_outline() const;
|
|
void add_area_fill_point();
|
|
void run_area_fill();
|
|
void undo_last_area_fill();
|
|
std::vector<glm::dvec3> m_fill_points; // outline vertices (world space) in click order
|
|
std::vector<TAnimModel *> m_fill_last; // instances created by the most recent fill, for "Undo last fill"
|
|
std::vector<std::string> m_fill_custom; // user-assembled package of node templates
|
|
int m_fill_custom_idx{-1};
|
|
model_set_ref m_fill_source; // manual = m_fill_custom, otherwise a user set or node bank group
|
|
float m_fill_density{200.0f}; // objects per hectare
|
|
float m_fill_min_spacing{2.0f}; // minimal distance between placed objects (m)
|
|
bool m_fill_random_rotation{true}; // random yaw; otherwise the Functions panel rotation settings apply
|
|
float m_fill_scale_min{1.0f};
|
|
float m_fill_scale_max{1.0f};
|
|
bool m_fill_models_as_ground{true}; // large model instances (terrain tiles) count as ground
|
|
std::string m_fill_status; // result of the last fill, shown in the panel
|
|
|
|
// array: copies of the selected model set out in a row, after the array modifier of Blender
|
|
struct array_settings
|
|
{
|
|
int fit{0}; // 0: fixed count, 1: as many as the length takes
|
|
int count{2}; // the model itself included
|
|
float length{10.0f}; // m
|
|
bool relative{true};
|
|
glm::vec3 relative_offset{1.0f, 0.0f, 0.0f}; // of the size of the model, along its axes
|
|
bool constant{false};
|
|
glm::vec3 constant_offset{1.0f, 0.0f, 0.0f}; // m, along the axes of the model
|
|
float turn{0.0f}; // degrees around the vertical axis, each copy against the one before it
|
|
bool ground{false}; // the copies are put as high over the ground as the model is
|
|
bool operator==(array_settings const &) const = default;
|
|
};
|
|
struct array_tool
|
|
{
|
|
static constexpr int limit = 1000; // models in an array, so a slip of the finger doesn't freeze the editor
|
|
static constexpr double minimal_step = 0.001; // m, copies any closer would sit in one another
|
|
array_settings settings;
|
|
// the array made last, which follows the settings until something else is selected or changed
|
|
TAnimModel *base{nullptr}; // model it was made of, nullptr if there's none
|
|
std::size_t step{0}; // size of the undo history with the array at its top
|
|
array_settings applied; // what the copies were set out with
|
|
glm::dvec3 location{0.0}; // of the model then
|
|
glm::vec3 angles{0.0f};
|
|
glm::vec3 scale{1.0f};
|
|
// size of the model asked about last
|
|
TModel3d const *sized{nullptr};
|
|
glm::vec3 size{0.0f};
|
|
std::string status; // outcome of the last operation, shown in the panel
|
|
};
|
|
array_tool m_array;
|
|
void render_array();
|
|
// size of the model of specified instance along its axes, the scale of the instance left out
|
|
glm::vec3 array_size(TAnimModel const &Base);
|
|
// offset of each copy from the one before it, along the axes of the model
|
|
glm::dvec3 array_offset(TAnimModel const &Base);
|
|
// number of the models in the array, the one it's made of included. Step: length of the offset
|
|
int array_count(double const Step) const;
|
|
// location and angles of each copy in turn
|
|
std::vector<std::pair<glm::dvec3, glm::vec3>> array_placements(TAnimModel &Base);
|
|
// true while the array made last follows the settings
|
|
bool array_live() const;
|
|
void make_array();
|
|
// brings the copies of the array made last to what the settings ask for
|
|
void shape_array();
|
|
void update_array();
|
|
void restore_array_snapshot(EditorSnapshot Snapshot, std::vector<EditorSnapshot> &Opposite, bool const Undo);
|
|
|
|
// ImGuizmo-based transform gizmo for the selected node
|
|
enum class gizmo_operation { translate, rotate, scale };
|
|
void render_gizmo();
|
|
// gizmo settings, drawn in the toolset window
|
|
void render_gizmo_options();
|
|
// how the top view draws the tracks: as a combo with the colour of the rails, or as items of a menu
|
|
void render_top_tracks_choice(bool const Combo);
|
|
// the tools of the field of work in the toolbar under the menu
|
|
void render_toolbar();
|
|
// an edit mode of the node bank as the field of work, from the toolbar or its key (1-5)
|
|
void choose_edit_mode(nodebank_panel::edit_mode const Mode);
|
|
// fields of work of the editor, in the row above the toolbar: the models around, the tracks, the roads, the terrain
|
|
enum class work_area
|
|
{
|
|
surroundings,
|
|
tracks,
|
|
roads,
|
|
terrain
|
|
};
|
|
work_area current_work_area() const;
|
|
void choose_work_area(work_area const Area);
|
|
void render_workspaces();
|
|
bool m_gizmo_enabled{true}; // master switch for the in-viewport gizmo
|
|
bool m_track_gizmo_on{false}; // the gizmo in the tracks: off until Q, W or E, so a track isn't moved by chance
|
|
bool gizmo_shown() const; // the switch of the field of work in use
|
|
bool m_gizmo_using{false}; // tracks an ongoing drag, so a single undo snapshot is taken per drag
|
|
bool m_gizmo_local{false}; // manipulate in the object's local space instead of world space
|
|
gizmo_operation m_gizmo_op{gizmo_operation::translate}; // current transform mode (translate/rotate/scale)
|
|
float m_gizmo_snap{1.0f}; // translation snap step (metres) applied while Ctrl is held
|
|
|
|
TTrack *selected_track() const override;
|
|
bool track_editing() const override;
|
|
std::size_t history_revision() const override;
|
|
glm::dvec3 camera_position() const override;
|
|
track_hover const &hovered_track() const override;
|
|
std::vector<TTrack *> const &track_set() const override;
|
|
editor_track_tab current_track_tab() const override;
|
|
void render_path_ui();
|
|
void draw_track_overlay() const;
|
|
editor_track::point_ref track_handle_hit() const;
|
|
void select_track(scene::basic_node *Node);
|
|
void render_track_gizmo();
|
|
void commit_track_drag(bool const Force);
|
|
void cancel_track_tools();
|
|
void push_track_snapshot(std::vector<std::pair<TTrack *, editor_track::state>> States, std::vector<TTrack *> Created = {}, std::vector<TTrack *> Removed = {}) override;
|
|
void push_kilometrage_snapshot() override;
|
|
void set_current_node(scene::basic_node *Node) override;
|
|
alignment::limits const &route_norms() const override;
|
|
void clear_track_point() override;
|
|
editor_nmt &terrain_model() override;
|
|
double terrain_model_offset() const override;
|
|
bool terrain_model_fitted() const override;
|
|
// false, with the reason, when one of the paths can't be changed, its file not taking the changes back
|
|
static bool tracks_editable(std::vector<TTrack *> const &Tracks, std::string &Reason);
|
|
void trim_history();
|
|
void restore_track_snapshot(EditorSnapshot const &Snapshot, std::vector<EditorSnapshot> &Opposite, bool const Undo);
|
|
// changes of the kept alignments and switches go into the last step of the history, made just before them
|
|
void records_to_history();
|
|
// the paths a drag of the gizmo takes, to tell after it what became of the kept alignments and switches
|
|
struct record_watch
|
|
{
|
|
bool active{false};
|
|
std::vector<TTrack *> moving;
|
|
std::vector<std::pair<glm::dvec3, glm::dvec3>> before; // ends of the first path of each moving track
|
|
std::map<int, std::vector<TTrack *>> on; // the kept alignments and the moving paths on them
|
|
std::set<int> whole; // the kept alignments all of whose paths move
|
|
} m_record_watch;
|
|
void records_watch_begin();
|
|
void records_watch_end();
|
|
editor_track::point_ref m_track_point;
|
|
std::vector<TTrack *> m_track_drag;
|
|
std::vector<std::pair<TTrack *, editor_track::point_ref>> m_track_drag_points;
|
|
std::vector<editor_track::joint> m_track_joints; // of the neighbours, following the whole track dragged
|
|
editor_track::snap_target m_track_snap;
|
|
glm::dvec3 m_track_pivot{0.0};
|
|
glm::mat4 m_track_gizmo{1.0f};
|
|
bool m_track_gizmo_using{false};
|
|
struct track_gizmo_drag
|
|
{
|
|
gizmo_operation operation{gizmo_operation::translate};
|
|
bool control{false};
|
|
double angle{0.0};
|
|
int path{-1};
|
|
bool atend{true};
|
|
std::size_t pieces{1};
|
|
std::vector<segment_data> paths;
|
|
editor_track::point_ref point;
|
|
glm::dvec3 origin{0.0};
|
|
glm::dvec3 axis{0.0};
|
|
double grabbed{0.0};
|
|
double length{0.0};
|
|
double stretch{0.0};
|
|
std::vector<std::pair<TTrack *, editor_track::point_ref>> partners;
|
|
glm::dvec3 fixed{0.0};
|
|
std::vector<std::pair<TTrack *, std::vector<int>>> held;
|
|
std::vector<TTrack *> extra;
|
|
int ring{-1};
|
|
glm::dmat3 basis{1.0};
|
|
glm::dvec3 pivot{0.0};
|
|
double grade{0.0};
|
|
double roll{0.0};
|
|
double roll0{0.0};
|
|
double pivot_chainage{0.0};
|
|
std::vector<double> chainages;
|
|
std::vector<double> lengths;
|
|
struct switch_joint
|
|
{
|
|
TTrack *track{nullptr};
|
|
editor_track::point_ref own;
|
|
editor_track::point_ref theirs;
|
|
glm::dvec3 point{0.0};
|
|
glm::dvec3 tangent{0.0};
|
|
double roll{0.0};
|
|
bool moved{false};
|
|
std::vector<std::pair<TTrack *, std::vector<segment_data>>> cluster;
|
|
std::vector<std::pair<TTrack *, std::vector<editor_track::joint>>> joints;
|
|
};
|
|
std::vector<switch_joint> switches;
|
|
};
|
|
track_gizmo_drag m_track_gizmo_drag;
|
|
gizmo_operation track_gizmo_operation(TTrack const &Track, bool const Pointmode) const;
|
|
glm::mat4 track_gizmo_frame(TTrack const &Track, bool const Pointmode, gizmo_operation const Operation) const;
|
|
void track_gizmo_hold();
|
|
void track_gizmo_settle();
|
|
void track_gizmo_stretch(TTrack &Track, double const Length);
|
|
void track_gizmo_control(TTrack &Track, glm::dvec3 Control);
|
|
void track_gizmo_point(TTrack &Track, glm::dvec3 const &Position);
|
|
void track_gizmo_switches(TTrack &Track);
|
|
void track_gizmo_conform(TTrack &Track) const;
|
|
bool track_gizmo_clustered(TTrack const *Track) const;
|
|
void track_gizmo_spill(TTrack &Track, std::size_t const Pieces);
|
|
void track_gizmo_carry(track_gizmo_drag::switch_joint &Link, glm::dvec3 const &Point, glm::dvec3 const &From, glm::dvec3 const &To, double const Grade);
|
|
void track_gizmo_roll_switch(track_gizmo_drag::switch_joint const &Link, double const Roll);
|
|
void track_gizmo_take_joints(TTrack &Track);
|
|
void track_gizmo_take_points(TTrack &Track);
|
|
void track_gizmo_take_partners(TTrack &Track);
|
|
void track_gizmo_take_switch_joints(TTrack &Track, bool const Controlmode);
|
|
track_gizmo_drag::switch_joint track_gizmo_link(TTrack &Track, editor_track::point_ref const &Own, std::pair<TTrack *, editor_track::point_ref> const &Connection, std::function<bool(TTrack const *)> const &Movable);
|
|
void track_gizmo_take_switches(TTrack &Track);
|
|
// the other switch of a double switch and the track between them go with the moved or turned switch as a whole
|
|
void track_gizmo_take_double(TTrack &Track);
|
|
void track_gizmo_measure_rotation(TTrack &Track, bool const Pointmode);
|
|
void track_gizmo_measure(TTrack &Track, bool const Pointmode, gizmo_operation const Operation);
|
|
void track_gizmo_begin(TTrack &Track, bool const Pointmode, gizmo_operation const Operation);
|
|
void track_gizmo_turn_direction(TTrack &Track, double const Angle);
|
|
void track_gizmo_turn_grade(TTrack &Track, double const Angle);
|
|
void track_gizmo_turn_cant(TTrack &Track, double const Angle);
|
|
void track_gizmo_turn(TTrack &Track, int const Axis, double const Angle);
|
|
void track_gizmo_rotated(TTrack &Track);
|
|
void track_gizmo_scaled(TTrack &Track);
|
|
void track_gizmo_moved_point(TTrack &Track, glm::dvec3 const &Position);
|
|
void track_gizmo_length(TTrack &Track, double Length);
|
|
void track_gizmo_end(TTrack &Track);
|
|
bool m_track_dirty{false};
|
|
bool m_track_drag_on_the_way{false}; // committed, but not as the end of the drag
|
|
std::chrono::steady_clock::time_point m_track_last_commit;
|
|
editor_track::state m_track_field_before;
|
|
// the event to add to the path, typed
|
|
TTrack const *m_track_events_for{nullptr};
|
|
std::array<char, 128> m_track_event{};
|
|
int m_track_event_list{0};
|
|
std::string m_track_events_missing;
|
|
void render_path_events(TTrack &Track);
|
|
std::string m_track_mode_notice;
|
|
struct route_design
|
|
{
|
|
TTrack *from{nullptr};
|
|
TTrack *to{nullptr};
|
|
editor_track::chain chain;
|
|
std::string error;
|
|
std::string status;
|
|
alignment::design design;
|
|
alignment::result result;
|
|
int vertex{-1};
|
|
int grip{-1};
|
|
bool single{true}; // one curve between its straights, instead of the whole line
|
|
bool relaying{false}; // the crossovers of the line were taken out, they go back once it's laid
|
|
// crossovers taken out with a line which didn't fit it laid again, tried again as the other lines are laid
|
|
struct crossover_out
|
|
{
|
|
int shape{-1};
|
|
glm::dvec3 press{0.0}, release{0.0};
|
|
std::string name;
|
|
std::vector<std::string> names; // of the switches at the press and at the release
|
|
};
|
|
std::vector<crossover_out> crossovers_out;
|
|
double origin{0.0}; // km of the start, m
|
|
int designed{0}; // vertices whose parameters came from the alignment kept in the scenery
|
|
int departed{-1}; // alignment kept in the scenery near the fragment, which its paths no longer follow
|
|
double departure{0.0};
|
|
// the band of the curvature in the panel: the element under the mouse, the point of it, and what's dragged in it
|
|
struct curvature_band
|
|
{
|
|
int hot{-1};
|
|
double at{-1.0};
|
|
int vertex{-1};
|
|
int part{0}; // 1 the radius, 2 the transition in, 3 the transition out, 4 the transition between two arcs of a compound curve
|
|
int arc{0}; // the arc of a compound curve the radius is of, 0 the first; of a transition between arcs the one after it
|
|
double value{0.0};
|
|
ImVec2 press{0.0f, 0.0f};
|
|
float metres{1.0f}; // pixels of a metre and of a unit of the curvature, kept as the drag goes
|
|
float curvature{1.0f};
|
|
} band;
|
|
// the part of a curve whose field the mouse is over in the panel, or which is being edited there, shown in the view
|
|
struct curve_focus
|
|
{
|
|
enum class part
|
|
{
|
|
whole,
|
|
entry,
|
|
exit,
|
|
arc, // of the radius `arc`, the first one 0
|
|
between // the transition leading into the arc of the radius `arc`
|
|
};
|
|
int vertex{-1};
|
|
part what{part::whole};
|
|
int arc{0};
|
|
bool held{false}; // by a field being edited, the mouse over the others doesn't move it
|
|
} focus;
|
|
// the points clicked when the fragment was laid, kept with its design: the curves keep to them as their transitions and cants
|
|
// change, while hold is on
|
|
std::vector<glm::dvec3> clicks;
|
|
bool hold{true};
|
|
struct click_state
|
|
{
|
|
double offset{0.0}; // from the line, m
|
|
int vertex{-1}; // whose curve it's a point of
|
|
bool corner{false}; // a bend of straights clicked, the vertex itself rather than a point of its curve
|
|
};
|
|
std::vector<click_state> click_states; // as the line was at the revision measured
|
|
int revision{0}; // of the result, counted as it's computed
|
|
int measured{-1};
|
|
// points clicked along the middle of the track seen on the orthophoto, the radii of the curves and their shares fitted to them after each click
|
|
struct trace_state
|
|
{
|
|
bool active{false};
|
|
int radii{0}; // 0: as many as the points need, up to three
|
|
std::vector<glm::dvec3> points;
|
|
alignment::design before; // taken back by Esc
|
|
double rms{0.0};
|
|
double worst{0.0};
|
|
} trace;
|
|
};
|
|
void render_route_ui();
|
|
bool render_route_band();
|
|
bool render_route_parameters();
|
|
bool render_route_vertices();
|
|
bool render_route_vertex(int const Index);
|
|
void render_route_result();
|
|
void render_route_trace();
|
|
// the camera over the stretch of the line between the chainages, a curve seen whole
|
|
void route_show_curve(double const From, double const To);
|
|
// the departures of the points clicked from the line and the curves they belong to, measured again when the line changed
|
|
void route_measure_clicks();
|
|
// the points clicked along the curve of the vertex, in the plan, the bends of straights left out
|
|
std::vector<glm::dvec2> route_clicks_of(int const Vertex) const;
|
|
// the radii of the curve of the vertex fitted again to the points clicked along it, its transitions and cants as they are
|
|
bool route_hold_clicks(int const Vertex);
|
|
// the elements of the part of the curve in focus in the panel, in their order along the line
|
|
std::vector<std::size_t> route_focused() const;
|
|
void route_trace_start();
|
|
void route_trace_fit();
|
|
void route_trace_end(bool const Keep);
|
|
int route_trace_hit() const;
|
|
glm::dvec3 route_trace_cursor() const;
|
|
void route_reset();
|
|
void route_bind_ends();
|
|
bool route_from_curve(TTrack &Track);
|
|
bool route_from_line(TTrack &Track);
|
|
// the first curve of the design and the last one going on from the curves of the tracks adjoining, where they turn their way: a
|
|
// curve cut by a switch bent into it, say. Lays the design
|
|
void route_curved_ends();
|
|
alignment::vertex route_vertex_of(editor_track::curve const &Curve) const;
|
|
bool route_load(TTrack &Track);
|
|
void route_read_stored(TTrack &Track);
|
|
void route_take_stored(int const Index);
|
|
void record_switch(TTrack &Track, editor_track::switch_template const &Shape);
|
|
void record_double(TTrack &First, TTrack &Second, editor_track::switch_template const &Shape);
|
|
// the two switches of a double switch and the plain track between them, found from any of the three
|
|
struct double_switch
|
|
{
|
|
TTrack *first{nullptr};
|
|
TTrack *link{nullptr};
|
|
TTrack *second{nullptr};
|
|
};
|
|
std::optional<double_switch> double_of(TTrack const &Track) const;
|
|
// a slip of the scenery the track is a part of: its switches, all its tracks, the switches among them, and its ends where it joins
|
|
// the tracks around, A and B of its first track through, C and D of the other one, with the way into the slip at each
|
|
struct slip_set
|
|
{
|
|
switch_store::record record;
|
|
std::vector<TTrack *> switches;
|
|
std::vector<TTrack *> parts;
|
|
std::array<glm::dvec3, 4> ends{};
|
|
std::array<glm::dvec2, 4> into{};
|
|
};
|
|
std::optional<slip_set> slip_of(TTrack const &Track) const;
|
|
// the two tracks of the slip through it from end to end, as they cross where it's taken out
|
|
static std::array<segment_data, 2> slip_throughs(slip_set const &Slip);
|
|
// the slip taken out with its record, nothing of it put in the history yet; with Throughs its two tracks laid crossing in its
|
|
// place, given back
|
|
std::vector<TTrack *> slip_taken_out(slip_set const &Slip, bool const Throughs);
|
|
// the record of the crossing of two plain tracks the track is one of
|
|
std::optional<switch_store::record> crossing_record(TTrack const &Track) const;
|
|
// the paths of the set in the order editor_track::place_switch gives them
|
|
static std::vector<segment_data> double_paths(double_switch const &Set);
|
|
// the switch of the template, or the two switches of a double one with the plain track between them, committed and recorded
|
|
std::vector<TTrack *> create_switch_set(editor_track::switch_template const &Shape, std::vector<segment_data> const &Paths, TTrack const &Style, std::string const &Name);
|
|
// with no Style, as the lay tool lays its tracks
|
|
std::vector<TTrack *> create_switch_set(editor_track::switch_template const &Shape, std::vector<segment_data> const &Paths, TTrack const *Style, std::string const &Name);
|
|
void record_slip(std::vector<TTrack *> const &Parts, std::string const &Kind, std::string const &Type, double const Radius, double const Angle, std::string const &Base, double const Middle = 0.0);
|
|
void render_switch_record(TTrack const &Track) const;
|
|
void route_store();
|
|
bool digitize_drawn(std::vector<TTrack *> const &Created, bool const Alone = true) override;
|
|
bool digitize_chain(editor_track::chain const &Chain, std::string *Reason = nullptr, TTrack **Culprit = nullptr);
|
|
int digitize_parts(editor_track::chain const &Chain, std::string *Reason, int &Skipped);
|
|
// the lines kept, the paths left out
|
|
void digitize_all(int *Kept = nullptr, int *Failed = nullptr);
|
|
// what the digitization of the scenery did, or would do
|
|
struct digitize_report
|
|
{
|
|
int lines{0};
|
|
int lines_failed{0};
|
|
int switches{0};
|
|
int known{0}; // kept in the scenery already
|
|
int designed{0}; // of a template of the catalogue
|
|
int measured{0};
|
|
int slips{0};
|
|
int unnamed{0}; // no record finds them
|
|
int odd{0};
|
|
int recorded{0};
|
|
int crossovers{0};
|
|
int crossovers_known{0};
|
|
int crossovers_recorded{0};
|
|
int crossovers_odd{0};
|
|
int found{0};
|
|
int bound{0};
|
|
std::map<std::string, int> types; // of the catalogue
|
|
std::map<std::string, int> shapes; // measured
|
|
std::vector<std::string> notes;
|
|
};
|
|
// the switches without a type kept get the one of the catalogue they are of, or the size measured from their shape
|
|
void digitize_switches(digitize_report &Report, bool const Write);
|
|
// two switches facing each other from two tracks, their diverging tracks joined by a plain one, are kept as a crossover
|
|
void digitize_crossovers(digitize_report &Report, bool const Write);
|
|
// the lines, the switches, the crossovers and the objects along the tracks at one go; without Write only counts them
|
|
std::string digitize_scenery(bool const Write);
|
|
void render_route_stored();
|
|
void route_update()
|
|
{
|
|
m_route.design.norms.checked = true;
|
|
m_route.result = alignment::compute(m_route.design);
|
|
++m_route.revision;
|
|
}
|
|
void route_apply();
|
|
void route_lay();
|
|
bool route_relay_through_switches(editor_track::chain const &Chain, std::vector<std::pair<TTrack *, editor_track::state>> &States, std::vector<TTrack *> &Created, TTrack *&Last);
|
|
void route_recommend(alignment::vertex &Vertex) const;
|
|
void draw_route_overlay() const;
|
|
void render_route_gizmo();
|
|
glm::dvec3 route_vertex_position(int const Vertex) const;
|
|
bool route_active() const;
|
|
route_design m_route;
|
|
|
|
struct straights_state
|
|
{
|
|
editor_track::straight_tolerance tolerance;
|
|
double minimum_length{50.0};
|
|
std::vector<editor_track::straight> found;
|
|
int listed{-1};
|
|
TTrack *current_for{nullptr};
|
|
editor_track::straight current;
|
|
std::vector<editor_track::straight> neighbours;
|
|
std::vector<double> spacings{3.5, 4.0, 4.5, 4.75, 5.0, 5.5, 6.0};
|
|
char filter[32]{};
|
|
int handle{-1};
|
|
bool dragging{false};
|
|
editor_track::straight drag_line;
|
|
std::vector<editor_track::straight> set;
|
|
std::vector<editor_track::straight> drag_lines;
|
|
bool fitting{false};
|
|
editor_track::curve fit_before;
|
|
editor_track::curve fit_after;
|
|
bool fit_has_before{false};
|
|
bool fit_has_after{false};
|
|
std::vector<std::pair<TTrack *, editor_track::state>> drag_states;
|
|
std::size_t drag_step{0};
|
|
glm::dvec3 preview_start{0.0};
|
|
glm::dvec3 preview_end{0.0};
|
|
glm::dvec3 edit_start{0.0};
|
|
glm::dvec3 edit_end{0.0};
|
|
double edit_length{0.0};
|
|
double edit_azimuth{0.0};
|
|
double distance{4.0};
|
|
double curve_radius{0.0};
|
|
bool auto_transitions{true};
|
|
double transition{0.0};
|
|
int tool{0};
|
|
int tool_before{0};
|
|
bool tool_mouse{false};
|
|
std::vector<glm::dvec3> detour;
|
|
editor_track::straight detour_line;
|
|
glm::dvec3 detour_mouse{0.0};
|
|
bool tool_placed{false};
|
|
double tool_at{0.0};
|
|
glm::dvec3 tool_point{0.0};
|
|
glm::dvec3 tool_handle{0.0};
|
|
editor_track::straight tool_line;
|
|
std::string status;
|
|
};
|
|
void render_straights_ui();
|
|
void draw_straights_overlay() const;
|
|
editor_track::straight const ¤t_straight();
|
|
bool straights_active();
|
|
void render_straight_gizmo();
|
|
void straight_apply(editor_track::straight const &Line, glm::dvec3 const &Start, glm::dvec3 const &End);
|
|
void straights_apply(std::vector<editor_track::straight> const &Lines, std::vector<std::pair<glm::dvec3, glm::dvec3>> const &Ends);
|
|
bool in_straight_set(editor_track::straight const &Line) const;
|
|
bool place_straight_tool();
|
|
void apply_straight_tool();
|
|
double straight_tool_radius(editor_track::straight const &Line) const;
|
|
void straight_reshape(editor_track::straight const &Line, double const From, double const To, std::function<glm::dvec3(glm::dvec3 const &)> const &Tail, double const Radius);
|
|
void straight_refresh() override;
|
|
bool start_curve_fit(editor_track::straight const &Line, int const Handle);
|
|
void update_curve_fit(glm::dvec3 const &Start, glm::dvec3 const &End);
|
|
void add_detour_point();
|
|
void apply_detour();
|
|
std::vector<glm::dvec3> detour_outline() const;
|
|
void find_neighbour_straights();
|
|
// listed spacing of a neighbouring straight the line can snap to, if it is close enough
|
|
struct parallel_offer
|
|
{
|
|
bool nearby{false};
|
|
bool snaps{false};
|
|
double spacing{0.0};
|
|
double distance{0.0};
|
|
double angle{0.0}; // deg between the two straights
|
|
double correction{0.0}; // m along the line normal to reach the spacing
|
|
editor_track::straight const *neighbour{nullptr};
|
|
};
|
|
parallel_offer straight_parallel_offer(editor_track::straight const &Line, glm::dvec3 const &Offset) const;
|
|
glm::dvec3 snap_straight_offset(editor_track::straight const &Line, glm::dvec3 const &Offset) const;
|
|
glm::dvec3 snap_straight_direction(glm::dvec3 const &Pivot, glm::dvec3 const &Moved) const;
|
|
straights_state m_straights;
|
|
|
|
struct curve_sample
|
|
{
|
|
double station{0.0};
|
|
glm::dvec3 position{0.0};
|
|
glm::dvec2 tangent{0.0, 1.0};
|
|
float roll{0.f};
|
|
float radius{0.f};
|
|
};
|
|
// the line leaving an end of a switch off its main straight, taken before the switch moves: its paths up to the end of
|
|
// the straight past the curve next to the switch. When the switch moves only the paths up to a joint on that straight
|
|
// are laid again, so the curve keeps to the end of the switch and the rest of the network stays where it is
|
|
struct switch_branch
|
|
{
|
|
std::size_t joint{0};
|
|
editor_track::chain chain;
|
|
std::size_t straight{0}; // the first path of the straight past the curve
|
|
alignment::design design; // as the paths lie
|
|
alignment::result result;
|
|
// made for the new end of the switch
|
|
editor_track::chain part; // the paths laid again
|
|
std::vector<segment_data> pieces;
|
|
alignment::design laid; // of the whole chain
|
|
double factor{1.0}; // of the radius and the transitions of the curve
|
|
};
|
|
struct switch_tool
|
|
{
|
|
std::vector<std::string> keep_names; // the names the switches laid next take, before the ones of the tool
|
|
std::string keep_slip; // the name the slip or the crossing laid next takes, of the one it's laid in place of
|
|
bool curved{false};
|
|
// a switch placed where there's no track: started on the ground, or at the free end it goes on from in its direction; the direction
|
|
// of its main track taken from the drag once it's long enough, then the drag sideways gives the side of the diverging one
|
|
bool free{false};
|
|
editor_track::snap_target free_end;
|
|
std::optional<glm::dvec2> free_heading;
|
|
// from a free end, dragged on past its end: bent, its diverging track turning the other way than the main one, the same way with
|
|
// Tab (one-sided)
|
|
bool one_sided{false};
|
|
std::vector<curve_sample> frame;
|
|
std::vector<TTrack *> frame_tracks;
|
|
std::vector<editor_track::switch_template> templates;
|
|
bool collected{false};
|
|
int armed{-1};
|
|
int last{0}; // template armed the last time
|
|
bool placing{false};
|
|
// where it was pressed on the screen: let go no farther from there, the press places nothing, a click doesn't lay a switch by chance
|
|
glm::vec2 pressed_at{0.f};
|
|
double along{0.0};
|
|
double pressed{0.0}; // along a curve: where the press was, the start of the switch drawn from it to the ends of the cant ramps
|
|
glm::dvec3 point{0.0};
|
|
glm::dvec3 mouse{0.0};
|
|
editor_track::straight line;
|
|
std::string status;
|
|
char name[64]{};
|
|
struct drive_family
|
|
{
|
|
std::string name;
|
|
std::array<std::string, 4> files;
|
|
std::array<double, 4> heights{};
|
|
bool preferred{false};
|
|
};
|
|
std::vector<drive_family> drives;
|
|
int drives_revision{-1}; // of the include bank the drives were read from
|
|
int drive{-1};
|
|
int drive_side{0};
|
|
struct slide_state
|
|
{
|
|
bool active{false};
|
|
TTrack *track{nullptr};
|
|
glm::vec2 pressed{0.f};
|
|
double grip{0.0};
|
|
double low{0.0};
|
|
double high{0.0};
|
|
double distance{0.0};
|
|
double length{0.0};
|
|
std::vector<double> joints;
|
|
// the lines leaving the switch off its straight: the joint they leave at, the path of the switch in the shown ones
|
|
struct branch_line
|
|
{
|
|
editor_track::joint joint;
|
|
std::size_t path{0};
|
|
switch_branch branch;
|
|
};
|
|
std::vector<branch_line> branches;
|
|
// a switch bent into a curve slides along it: the curve its main track and the tracks next to it make, where the switch
|
|
// starts on it; low and high the distances it may go back and on
|
|
std::vector<curve_sample> frame;
|
|
double station{0.0};
|
|
};
|
|
slide_state slide;
|
|
double slide_typed{0.0};
|
|
int connection{-1};
|
|
int connection_kind{0}; // the kind of connection chosen last, taken again when the connections are chosen
|
|
std::string rail_pick{"60E1"}; // the rail whose templates are listed first where the track doesn't tell its rail
|
|
int connection_second{-1};
|
|
double connection_radius{0.0};
|
|
double connection_gap{6.0};
|
|
bool connection_together{false};
|
|
char connection_spacings[64]{"4.75;4.75;5.0"};
|
|
double connection_stub{25.0};
|
|
// the connection a switch dragged makes, as where it's let go tells it, in connection then: let go on the other track a
|
|
// crossover, across the tracks between them a ladder; by a crossover there already turned the other way a double crossover
|
|
// with it, over it a scissors one
|
|
bool recognised{false};
|
|
TTrack *partner{nullptr}; // a switch of the crossover there already
|
|
};
|
|
switch_tool m_switch;
|
|
// what the switch tool places: a switch into a straight or a curve, a slip switch or a crossing at a crossing of two
|
|
// straights, or a connection of tracks laid whole
|
|
enum class switch_kind
|
|
{
|
|
single,
|
|
slip,
|
|
crossing,
|
|
connection
|
|
};
|
|
switch_kind current_switch_kind() const;
|
|
void choose_switch_kind(switch_kind const Kind);
|
|
bool switch_kind_offered(switch_kind const Kind) const;
|
|
bool plan_connection(connection::request &Request, connection::result &Result) const;
|
|
// what the drag of the switch being placed makes, from where the cursor is: sets connection and partner of the tool
|
|
void recognise_connection();
|
|
// the double or the scissors crossover of the partner and the crossover dragged, on the lines of their tracks
|
|
bool plan_partner_connection(connection::request &Request, connection::result &Result) const;
|
|
void insert_partner_connection();
|
|
// the switches and the inserts of the connection planned laid, one step of the history. false if they don't fit
|
|
bool lay_planned_connection(connection::request const &Request, connection::result const &Plan, TTrack *Style);
|
|
void insert_connection();
|
|
void render_connection_options();
|
|
// the name of a kind of connection of tracks, translated
|
|
static char const *connection_name(int const Kind);
|
|
// the name of a switch template for the lists: where it comes from and its name without the lengths
|
|
static std::string switch_template_label(editor_track::switch_template const &Template);
|
|
// the name of a switch template for the user: translated, with the speed on its diverging track
|
|
static std::string template_name(editor_track::switch_template const &Template);
|
|
// the template of the catalogue a record of the switches was laid of, -1 if none: Lengths compares a and b too, which the
|
|
// record of a connection keeps for its spacing; Movable: the nose of the frog, either when not given
|
|
int matching_template(switch_store::record const &Record, bool const Lengths, std::optional<bool> const Movable = std::nullopt) const;
|
|
// the template the switch was laid of, -1 if none: a switch of the scenery of its own shape, say
|
|
int switch_template_index(TTrack const &Switch) const;
|
|
// why the switch can't take another template here, empty when it can
|
|
std::string template_change_blocked(TTrack const &Switch) const;
|
|
// the template of the catalogue a slip or a crossing was laid of, of the rail before the others; -1 if none
|
|
int slip_template_index(switch_store::record const &Record, std::string const &Rail) const;
|
|
// the switch of the template of the index in place: its start and its side kept, the tracks it joins following; a switch of a
|
|
// crossover takes the crossover with it, laid again, a slip or a crossing is laid again where its tracks cross. One step of the
|
|
// history; the status says how it went
|
|
bool change_switch_template(TTrack &Switch, int const Index);
|
|
bool change_slip_template(TTrack &Part, int const Index);
|
|
// the switch, or the double switch it's a part of, given the shape in place, straight or bent into the curve it lies in; Flip:
|
|
// the diverging track to the other side. Notes: for the user
|
|
bool apply_switch_template(TTrack &Switch, editor_track::switch_template const &Shape, bool const Flip, std::string &Notes);
|
|
// the template to choose: the speeds on the diverging track as chips, the templates of the rail by their skos, all the others
|
|
// folded under. Fits: those of the kind wanted; Rail: of the track, empty when it doesn't tell; Popup: inside a combo, with no
|
|
// windows of its own. Gives the index picked, -1 while none is
|
|
int render_template_picker(char const *Id, std::function<bool(editor_track::switch_template const &)> const &Fits, std::string const &Rail, int const Chosen, bool const Popup);
|
|
// the template of the selected switch, slip or crossing, changed with a pick: in a combo for the inspector, else in full; nothing
|
|
// for another track
|
|
void render_switch_template(TTrack &Track, bool const Combo);
|
|
std::string connection_readout(connection::result const &Plan) const;
|
|
editor_track::straight straight_near(glm::dvec3 const &Point, std::vector<TTrack const *> const &Exclude, double const Reach) const;
|
|
editor_track::straight straight_through(glm::dvec3 const &Point, glm::dvec2 const &Direction) const;
|
|
void record_connection(connection::kind const Kind, std::vector<TTrack *> const &Switches, connection::result const &Plan, editor_track::switch_template const &Shape);
|
|
bool switch_room(TTrack &Track, double &Low, double &High, std::string &Reason);
|
|
bool switch_vacate(TTrack &Track, glm::dvec3 const &From, glm::dvec3 const &To, double const Shift, editor_track::straight const &Line, editor_track::edit &Edit, std::string &Status);
|
|
bool move_switch_paths(TTrack &Track, std::vector<segment_data> const &Paths, std::string &Status);
|
|
std::optional<switch_branch> take_switch_branch(TTrack const &Track, editor_track::joint const &Joint, std::size_t const Index) const;
|
|
// for the path of the switch the line leaves, as it'll lie
|
|
bool plan_switch_branch(segment_data const &Path, editor_track::joint const &Joint, switch_branch &Branch) const;
|
|
void lay_switch_branch(switch_branch const &Branch, editor_track::edit &Edit);
|
|
// of the joints off the main straight of the switch, the neighbours in Skip left out
|
|
std::vector<switch_branch> switch_branches(TTrack const &Track, std::vector<editor_track::joint> const &Joints, std::vector<TTrack const *> const &Skip = {}) const;
|
|
// for the paths the switch has now; the joints of the branches which can be laid are handled, the others are left out. Gives the notes for the user
|
|
std::string plan_switch_branches(TTrack const &Track, std::vector<editor_track::joint> const &Joints, std::vector<switch_branch> &Branches, std::vector<bool> &Handled) const;
|
|
// room on the straight of the whole double switch along the axis of its first switch, and the length of the set
|
|
bool double_room(double_switch const &Set, double &Low, double &High, double &Length, std::string &Reason);
|
|
bool move_double_paths(double_switch const &Set, std::vector<segment_data> const &Paths, std::string &Status);
|
|
bool slide_switch(TTrack &Track, double const Distance);
|
|
bool switch_slides(TTrack const &Track) const;
|
|
// a slip slid along its first track: the slip and the tracks its crossing track goes on into with their ends free move whole, the
|
|
// straights of its first track before it and past it give and take the length. Low and High: how far back and on it may go
|
|
struct slip_slide
|
|
{
|
|
glm::dvec3 shift{0.0}; // along its first track, a metre of it
|
|
std::vector<TTrack *> movers;
|
|
// where it joins the tracks of its first track before it and past it: at its ends A and B, or at the joints of its template
|
|
// with the straights out to them going along; those tracks, the end of each there
|
|
std::array<glm::dvec3, 2> joints{};
|
|
std::array<std::pair<TTrack *, editor_track::point_ref>, 2> ends{};
|
|
double low{0.0};
|
|
double high{0.0};
|
|
};
|
|
bool slip_room(slip_set const &Slip, slip_slide &Slide, std::string &Reason) const;
|
|
bool slide_slip(slip_set const &Slip, double const Distance);
|
|
// a switch bent into a curve, its main track going on into a plain track at each end: the curve the three make, the two tracks,
|
|
// where the switch starts on it; false for any other
|
|
bool bent_switch_frame(TTrack const &Track, std::vector<curve_sample> &Frame, std::array<TTrack *, 2> &Sides, double &Station) const;
|
|
// the paths of the switch moved along the curve by the distance, shaped as the curve is there
|
|
std::vector<segment_data> bent_switch_paths(TTrack const &Track, std::vector<curve_sample> const &Frame, double const Station, double const Distance) const;
|
|
bool slide_bent_switch(TTrack &Track, double const Distance);
|
|
// the switch bent into a curve given the paths, along the curve of the bent_switch_frame: the tracks next to it laid along it up to
|
|
// its new ends, one taken up whole going, the curve past the diverging track following. Notes: for the user
|
|
bool lay_bent_switch(TTrack &Track, std::vector<curve_sample> const &Frame, std::array<TTrack *, 2> const &Sides, std::vector<segment_data> const &Paths, std::string &Notes);
|
|
void switch_slide_start(TTrack &Track);
|
|
void switch_slide_update();
|
|
void switch_slide_finish();
|
|
void draw_switch_slide() const;
|
|
// reads the drives from the include bank once it changes; Wait: for the templates being looked for. true if it read them
|
|
bool scan_switch_drives(bool Wait = true);
|
|
std::string switch_name_for_new() const;
|
|
bool place_switch_drive(TTrack &Switch);
|
|
bool flip_switch_drive(TTrack &Switch);
|
|
void advance_switch_name();
|
|
void join_last_steps();
|
|
bool render_switch_drive_choice();
|
|
struct turntable_template
|
|
{
|
|
std::string file;
|
|
std::string name;
|
|
double length{0.0};
|
|
int angles{0};
|
|
int positions{0};
|
|
int track{0};
|
|
int yaw{0};
|
|
std::vector<double> fixed;
|
|
};
|
|
struct turntable_fit
|
|
{
|
|
editor_track::snap_target end;
|
|
double heading{0.0};
|
|
double radius{0.0};
|
|
double length{0.0};
|
|
std::vector<segment_data> pieces;
|
|
std::string issue;
|
|
bool chosen{true};
|
|
TTrack *replaces{nullptr};
|
|
};
|
|
struct turntable_tool
|
|
{
|
|
std::vector<turntable_template> templates;
|
|
int revision{-1}; // of the include bank the templates were read from
|
|
int chosen{-1};
|
|
char name[64]{};
|
|
bool placing{false};
|
|
glm::dvec3 centre{0.0};
|
|
double yaw{0.0};
|
|
glm::vec2 pressed{0.f};
|
|
editor_track::snap_target snap;
|
|
TTrack *table{nullptr};
|
|
scene::instance_handle include{0};
|
|
int kind{-1};
|
|
double length{0.0};
|
|
double table_yaw{0.0};
|
|
std::vector<double> exits;
|
|
float reach{80.f};
|
|
float radius{150.f};
|
|
float stub{25.f};
|
|
float step{0.f};
|
|
std::vector<turntable_fit> fits;
|
|
int hovered{-1};
|
|
double heading{0.0};
|
|
double exit_length{0.0};
|
|
std::string status;
|
|
std::string error;
|
|
};
|
|
turntable_tool m_turntable;
|
|
bool scan_turntables(bool Wait = true);
|
|
std::string turntable_name_for_new() const;
|
|
bool turntable_read(TTrack *Table);
|
|
std::vector<scene::instance_handle> turntable_includes(TTrack const &Table);
|
|
glm::dvec3 turntable_centre() const;
|
|
std::vector<double> turntable_lines() const;
|
|
double turntable_snap(double const Heading) const;
|
|
void turntable_finish_placement();
|
|
void turntable_place(glm::dvec3 const &Centre, double const Yaw);
|
|
bool turntable_fit_end(editor_track::snap_target const &End, turntable_fit &Fit) const;
|
|
void turntable_find_fits();
|
|
void turntable_build(std::vector<turntable_fit const *> const &Fits);
|
|
bool turntable_exit_at(glm::dvec3 const &Ground, double &Heading, double &Length) const;
|
|
void turntable_store_exits();
|
|
void render_turntable_ui();
|
|
void draw_turntable_overlay() const;
|
|
struct extend_tool
|
|
{
|
|
bool active{false};
|
|
TTrack *track{nullptr};
|
|
glm::dvec3 point{0.0};
|
|
glm::dvec2 direction{0.0, 1.0};
|
|
double grade{0.0};
|
|
glm::dvec3 mouse{0.0};
|
|
int path{0};
|
|
bool atend{true};
|
|
editor_track::snap_target origin;
|
|
editor_track::snap_target snap;
|
|
glm::vec2 pressed{0.f};
|
|
std::vector<TTrack *> line;
|
|
};
|
|
extend_tool m_extend;
|
|
// what a point clicked while laying is: a bend of the straights, eased with a large curve, or a point along the middle of a curve
|
|
// seen on the photo, the curve ending at the last of these
|
|
enum class lay_mode
|
|
{
|
|
straights,
|
|
curve
|
|
};
|
|
// a curve traced on the photo as it's laid, how far the points clicked along it are from it
|
|
struct lay_trace
|
|
{
|
|
std::vector<glm::dvec3> points;
|
|
std::vector<double> offsets;
|
|
double rms{0.0};
|
|
double worst{0.0};
|
|
std::size_t curves{0};
|
|
};
|
|
// the line the points clicked make: its design, the bends among its vertices, the curves traced
|
|
struct lay_line_plan
|
|
{
|
|
alignment::design design;
|
|
alignment::result shape;
|
|
std::vector<char> corners;
|
|
std::vector<lay_trace> traces;
|
|
// the straights of a fixed direction the next bend slides along: from a free end, out of a curve traced
|
|
std::vector<std::pair<glm::dvec3, glm::dvec3>> guides;
|
|
// where the grade breaks from point to point: the bends kept as such, at the heights clicked; a curve traced, or bends made
|
|
// one curve, goes at one grade from end to end
|
|
std::vector<glm::dvec3> knots;
|
|
};
|
|
// lays new track through the clicked points, with no path needed to start from
|
|
struct lay_tool
|
|
{
|
|
bool active{false};
|
|
std::vector<glm::dvec3> points;
|
|
std::vector<lay_mode> modes; // of the points, as each was clicked
|
|
lay_mode mode{lay_mode::straights};
|
|
int radii{0}; // of a curve traced: 0 as many as the points need, up to three
|
|
bool straights_between{true}; // a curve traced may be two with a straight between them
|
|
lay_line_plan plan; // of the line shown
|
|
editor_track::snap_target start; // free end the track starts from, if any
|
|
glm::dvec3 mouse{0.0};
|
|
editor_track::snap_target mouse_snap;
|
|
std::vector<segment_data> preview;
|
|
std::string preview_error;
|
|
double preview_length{0.0};
|
|
// the line worked out whole last, all its fits done: shown while the one of the cursor now still waits for them on the thread,
|
|
// so that the curves don't jump from one fit to the next as each comes
|
|
struct worked_out
|
|
{
|
|
std::vector<segment_data> preview;
|
|
std::string error;
|
|
double length{0.0};
|
|
lay_line_plan plan;
|
|
std::optional<alignment::lay_result> eased;
|
|
alignment::join_result join;
|
|
std::vector<glm::dvec3> points; // the ones clicked it was worked out for
|
|
};
|
|
std::optional<worked_out> shown;
|
|
// the cursor the line is being worked out for, kept till all its fits are done: what it was worked out from
|
|
struct settling_cursor
|
|
{
|
|
glm::dvec3 mouse{0.0};
|
|
editor_track::snap_target snap;
|
|
std::vector<glm::dvec3> points;
|
|
std::vector<lay_mode> modes;
|
|
lay_mode mode{lay_mode::straights};
|
|
int edits{0};
|
|
};
|
|
std::optional<settling_cursor> settling;
|
|
bool whole{true}; // false: each fit shown as it comes, as before, for a selftest to compare
|
|
double radius{500.0};
|
|
double piece_length{100.0};
|
|
bool copy_selected{false};
|
|
editor_track::path_style style;
|
|
bool own_speed{false}; // the speed of the style also where the track goes on from one with its own, the new tracks given it
|
|
std::string status;
|
|
double status_time{-100.0};
|
|
std::string skew; // what Alt turned the straight to
|
|
double escape_time{-100.0}; // when Esc was pressed over points not laid: the second Esc drops them
|
|
std::size_t history{0}; // the step of the history the track laid last was begun at
|
|
};
|
|
lay_tool m_lay;
|
|
alignment::limits laying_norms() const;
|
|
glm::dvec3 lay_angle_snap(glm::dvec3 const &Mouse, std::string &Label) const;
|
|
// the straight track Alt turns the laid straight to: the nearest one the straight from From to To crosses, or one along From
|
|
TTrack const *skew_reference(glm::dvec3 const &From, glm::dvec3 const &To, double const Reach) const;
|
|
void lay_after_history(bool const Undo);
|
|
void lay_back();
|
|
void lay_escape();
|
|
std::size_t lay_pending() const; // the points clicked and not laid yet
|
|
void render_lay_ui();
|
|
void render_lay_status();
|
|
void lay_click();
|
|
void lay_finish(editor_track::snap_target const &End);
|
|
void lay_cancel();
|
|
void lay_enter();
|
|
// Tab: the bends of straights or the curve traced, for the points clicked from now on
|
|
void lay_switch_mode();
|
|
// the points the same in number as their modes, a point with none a bend of straights
|
|
void lay_trim();
|
|
// the track through the points clicked, each the way its mode says; End: the free end it finishes at, the last point then
|
|
std::vector<segment_data> lay_pieces(std::vector<glm::dvec3> const &Points, std::vector<lay_mode> const &Modes, editor_track::snap_target const &End, double &Length, std::string &Error,
|
|
lay_line_plan *Plan = nullptr) const;
|
|
// Adjoining: the curve next to a free end on a curve goes on from its curvature, where it turns its way; else from a straight there
|
|
bool lay_line(std::vector<glm::dvec3> const &Points, std::vector<lay_mode> const &Modes, editor_track::snap_target const &End, lay_line_plan &Plan, std::string &Error, bool const Adjoining = true) const;
|
|
// whether the points next to the start of the line, or to its end, AtEnd, a free end joined there, are clicked along a curve
|
|
static bool traced_from(std::vector<glm::dvec3> const &Points, std::vector<lay_mode> const &Modes, bool const AtEnd);
|
|
// the curves of a stretch traced, the ones fitted lately kept for the same points
|
|
// none while the stretch the cursor moves along is still being fitted; Meanwhile: the fit done last of the same points but the one
|
|
// at the cursor until then
|
|
// Exact receives whether the fit is the one of these points, not one shown meanwhile; Going: the curve going on from the curve of the
|
|
// free end Base starts at, alignment::fit_going_on
|
|
std::optional<alignment::trace_stretch> traced_stretch(alignment::design const &Base, std::vector<glm::dvec2> const &Points, int const Radii, bool const Straights, bool const Meanwhile = true,
|
|
bool *Exact = nullptr, bool const Going = false) const;
|
|
// the curve through a row of bends clicked close along one, by traced_stretch
|
|
alignment::stretch_fit bends_fit() const
|
|
{
|
|
return [this](alignment::design const &Base, std::vector<glm::dvec2> const &Points) { return traced_stretch(Base, Points, 0, false, false); };
|
|
}
|
|
mutable std::vector<std::pair<std::vector<double>, alignment::trace_stretch>> m_stretch_cache;
|
|
// the stretch the cursor moves along is fitted on a thread, the frames drawn meanwhile with the fit done last
|
|
mutable alignment::stretch_fitter m_stretch_fitter;
|
|
// a fit the line asked the thread for isn't done yet: the line is one of the fits meanwhile
|
|
mutable bool m_fits_waiting{false};
|
|
// how much more the curve at the cursor was turned last to reach it, the first one tried for the next line
|
|
mutable double m_turned_last{0.0};
|
|
void render_switch_ui();
|
|
void render_switch_timbers();
|
|
void render_rail_profile_hint(TTrack &Track);
|
|
bool start_switch_placement();
|
|
void finish_switch_placement();
|
|
// a switch with no track under it: a press on the ground starts it at the free end of a track within reach, none with no free end near
|
|
editor_track::snap_target free_switch_end(glm::dvec3 const &Ground) const;
|
|
bool free_switch_offered() const;
|
|
void start_free_switch(glm::dvec3 const &Ground);
|
|
// the start of the switch, the way its main track goes and the side of its diverging one, as the drag gives them so far
|
|
void free_switch_pose(glm::dvec3 &Start, glm::dvec2 &Heading, int &Side, double &Grade) const;
|
|
// a switch laid on from a free end, dragged on past its end: bent, its main track turning toward the cursor
|
|
struct free_bend
|
|
{
|
|
double radius{0.0}; // of the main track
|
|
int turn{1}; // the way the main track turns, 1 to the left
|
|
int side{1}; // of the diverging track
|
|
std::vector<curve_sample> frame; // the curve the switch is bent into
|
|
std::vector<segment_data> paths;
|
|
switch_curve::switch_report report;
|
|
// a free end the cursor is at, which the main track leads into, the diverging one with Shift
|
|
editor_track::snap_target target;
|
|
bool diverging{false};
|
|
editor_track::branch_link link;
|
|
std::string problem; // why it can't lead into the target
|
|
};
|
|
// false where it isn't bent: near the switch, along the straight, or not from a free end
|
|
bool free_switch_bend(free_bend &Bend) const;
|
|
bool free_switch_bend_now(free_bend &Bend) const;
|
|
// laid on from an end of a switch: what the norms say of the change of the curvature from that switch to the tracks of this one
|
|
std::vector<std::string> free_switch_exits(std::vector<segment_data> const &Paths) const;
|
|
std::vector<segment_data> free_switch_paths() const;
|
|
void insert_free_switch();
|
|
std::vector<segment_data> switch_preview() const;
|
|
std::vector<segment_data> switch_preview_now() const;
|
|
// where a switch can't go, or doesn't go where it's dragged: what's in the way blinking in the view, each point told what's there,
|
|
// why by the cursor; while it's dragged, and a while after it's refused
|
|
struct switch_problem
|
|
{
|
|
std::string text;
|
|
std::vector<segment_data> paths;
|
|
std::vector<std::pair<glm::dvec3, std::string>> marks;
|
|
};
|
|
// what's at the end of the straight: a curve beginning, a switch, the track ending
|
|
std::string straight_end_note(editor_track::straight const &Line, bool const Far) const;
|
|
std::optional<switch_problem> switch_drag_problem() const;
|
|
std::optional<switch_problem> straight_switch_problem(editor_track::straight const &Line, double const Length, double const Along, int const Direction) const;
|
|
void flash_switch_problem(switch_problem Problem);
|
|
void flash_switch_problem(std::string const &Text, std::vector<segment_data> Paths, std::vector<std::pair<glm::dvec3, std::string>> Marks = {});
|
|
void draw_switch_problem(switch_problem const &Problem) const;
|
|
switch_problem m_switch_flash;
|
|
double m_switch_flash_until{-1.0};
|
|
// a preview worked out once a frame for the drawing and the readouts which all show it: the frame and the state of the tool it
|
|
// was worked out for
|
|
template <typename Result> struct frame_memo
|
|
{
|
|
int frame{-1};
|
|
std::vector<double> key;
|
|
Result result{};
|
|
bool fresh(std::vector<double> const &Key) const { return frame == ImGui::GetFrameCount() && key == Key; }
|
|
void keep(std::vector<double> Key, Result const &Value)
|
|
{
|
|
frame = ImGui::GetFrameCount();
|
|
key = std::move(Key);
|
|
result = Value;
|
|
}
|
|
};
|
|
std::vector<double> switch_memo_key() const;
|
|
mutable frame_memo<std::vector<segment_data>> m_switch_memo;
|
|
mutable frame_memo<std::pair<bool, free_bend>> m_bend_memo;
|
|
mutable frame_memo<std::vector<segment_data>> m_extend_memo;
|
|
void insert_switch(editor_track::straight const &Line, double const Along, int const Direction, int const Side);
|
|
void switch_placed(std::vector<TTrack *> const &Created);
|
|
static std::vector<curve_sample> sample_chain(editor_track::chain const &Chain);
|
|
static curve_sample sample_at(std::vector<curve_sample> const &Frame, double const Station);
|
|
// the curve a switch goes into as the norms look at it: its headings and its cant along it
|
|
std::vector<switch_curve::track_point> frame_points(std::vector<curve_sample> const &Frame) const;
|
|
// the way the switch being placed into a curve goes along it and the side its diverging track leaves to, from the drag
|
|
void curved_switch_pose(int &Direction, int &Side) const;
|
|
// the start of the switch being placed into a curve: where it was pressed, drawn to where the switch meets an end of a cant ramp or
|
|
// keeps 6 m off it; What receives which
|
|
double curved_switch_start(int const Direction, std::string *What = nullptr) const;
|
|
// the switch made of the paths, laid into the curve at the station, as ST-T1-A6 sees it
|
|
switch_curve::switch_report curved_switch_report(std::vector<segment_data> const &Paths, std::vector<curve_sample> const &Frame, double const Station, int const Direction) const;
|
|
static double nearest_station(std::vector<curve_sample> const &Frame, glm::dvec3 const &Point);
|
|
static std::vector<segment_data> curved_switch_paths(editor_track::switch_template const &Shape, std::vector<curve_sample> const &Frame, double const Station, int const Direction, int const Side);
|
|
// the path of a switch template laid into the curve: x of the template across the main track to the Side, z along it from the
|
|
// Station on, going Direction along the curve; past Bent along it going on straight as the curve heads there. The heights and the
|
|
// cant are those of the line where the point is along it
|
|
static segment_data frame_path(segment_data const &Local, std::vector<curve_sample> const &Frame, double const Station, int const Direction, int const Side, std::optional<double> const &Bent = std::nullopt);
|
|
void insert_curved_switch(int const Direction, int const Side);
|
|
// a crossover between two tracks running side by side along a curve (editormodeconnectioncurve.cpp)
|
|
struct curve_mapping;
|
|
// Beyond: the straights past the ends of the curve go with it up to that far, and a straight track that near the curve is taken
|
|
// as its part
|
|
static bool curve_of(TTrack &Track, editor_track::straight_tolerance const &Tolerance, double const Gauge, std::vector<curve_sample> &Frame, std::vector<TTrack *> &Tracks, double const Beyond = 0.0);
|
|
static void cut_curve(std::vector<TTrack *> &Candidates, std::vector<curve_sample> const &Frame, glm::dvec3 const &First, glm::dvec3 const &Second, std::vector<std::pair<TTrack *, editor_track::state>> &States, std::vector<TTrack *> &Created, std::vector<TTrack *> &Removed);
|
|
void insert_curved_connection();
|
|
struct curved_crossover
|
|
{
|
|
switch_store::record record;
|
|
TTrack *first{nullptr};
|
|
TTrack *second{nullptr};
|
|
TTrack *insert{nullptr};
|
|
};
|
|
// the single crossover the switch is a part of, along a curve or straights
|
|
std::optional<curved_crossover> crossover_of(TTrack const &Switch) const;
|
|
bool take_out_crossover(curved_crossover const &Crossover, std::vector<std::pair<TTrack *, editor_track::state>> &States, std::vector<TTrack *> &Created, std::vector<TTrack *> &Removed, TTrack *&First, TTrack *&Second);
|
|
bool slide_curved_connection(TTrack &Switch, double const Distance, int const Shape = -1);
|
|
// the template a crossover was laid of, -1 if it's not among the templates
|
|
int crossover_template(switch_store::record const &Record);
|
|
// a crossover laid again from the press on one track to the release by the other, as by the mouse. false if it doesn't fit
|
|
// Names: of the switch at the press and of the one at the release, kept when a crossover is laid again
|
|
bool lay_crossover(int const Shape, glm::dvec3 const &Press, glm::dvec3 const &Release, double const Reach = 3.0, std::vector<std::string> const &Names = {});
|
|
// after the grade line of the open route went on its paths: the line on the other side of each crossover of the route
|
|
// takes the same change of the heights where it runs beside, and its design with it. returns: how many lines followed
|
|
std::size_t follow_crossovers(std::vector<editor_track::route_sample> const &Before);
|
|
bool place_switch_on_straight(editor_track::straight const &Line, editor_track::switch_template const &Shape, TTrack const *Style, double const Along, int const Direction, int const Side, bool const Snap, std::vector<std::pair<TTrack *, editor_track::state>> &States, std::vector<TTrack *> &Created, std::vector<TTrack *> &Removed, std::string const &Name = {});
|
|
struct crossover_plan
|
|
{
|
|
editor_track::straight target;
|
|
editor_track::switch_template shape;
|
|
double along{0.0};
|
|
int direction{1};
|
|
int side{1};
|
|
std::vector<segment_data> inserts; // a straight one, or an aligning curve between straights onto a track not parallel
|
|
std::vector<segment_data> paths;
|
|
connection::result connection; // as it's kept with the two switches
|
|
};
|
|
bool plan_crossover(crossover_plan &Plan) const;
|
|
struct switch_link
|
|
{
|
|
editor_track::snap_target target;
|
|
editor_track::branch_link link;
|
|
double along{0.0};
|
|
int forward{1};
|
|
int side{1};
|
|
double moved{0.0};
|
|
std::vector<segment_data> paths;
|
|
std::string reason;
|
|
};
|
|
bool plan_switch_link(switch_link &Plan) const;
|
|
void insert_linked_switch(switch_link const &Plan);
|
|
bool plan_branch_link(editor_track::branch_link &Link, std::string &Reason) const;
|
|
void finish_branch_link(editor_track::branch_link const &Link);
|
|
std::string link_problem(editor_track::snap_target const &Target, editor_track::branch_link const &Link) const;
|
|
bool stretchable(editor_track::snap_target const &Target) const;
|
|
std::vector<TTrack *> link_tracks(editor_track::snap_target const &Target, editor_track::branch_link const &Link, TTrack const &Style, std::vector<std::pair<TTrack *, editor_track::state>> &States, std::vector<TTrack *> &Created);
|
|
bool cut_straight(editor_track::straight const &Line, double const From, double const To, std::vector<std::pair<TTrack *, editor_track::state>> &States, std::vector<TTrack *> &Created, std::vector<TTrack *> &Removed, TTrack **Style);
|
|
// where a slip or a crossing goes for the cursor at Point on the straight Line: the crossing of Line with the rail track
|
|
// nearest the cursor, or the double slip there to be replaced. With no track crossing there and Side given (1 to the left, -1 to
|
|
// the right of Line), the slip brings the crossing track along at its own angle, turning off to that side ahead
|
|
struct slip_plan
|
|
{
|
|
std::string problem;
|
|
std::string note;
|
|
bool lone{false}; // no track crosses Line by the cursor
|
|
TTrack *replaces{nullptr};
|
|
TTrack *other{nullptr}; // the crossing track, none where the slip brings it along
|
|
glm::dvec2 crossing{0.0};
|
|
glm::dvec2 first{0.0, 1.0};
|
|
glm::dvec2 direction{0.0, 1.0};
|
|
double angle{0.0};
|
|
double alongfirst{0.0};
|
|
double half{0.0};
|
|
// where the slip brings its crossing track along: from the crossing to the joints of its template, past the frogs of the diamond,
|
|
// the straights of both tracks laid out that far; the ends of the straights there, in the order of the points
|
|
double reach{0.0};
|
|
std::array<glm::dvec3, 4> ends{};
|
|
editor_track::slip_curve curve;
|
|
std::array<glm::dvec3, 4> points{};
|
|
};
|
|
bool plan_double_slip(editor_track::straight const &Line, glm::dvec3 const &Point, editor_track::switch_template const &Shape, slip_plan &Plan, int const Side = 0) const;
|
|
// a slip is made for its skos: where the tracks cross at another one, the refusal, which tells the template made for theirs; empty
|
|
// where it fits, and for a crossing
|
|
std::string slip_skew(editor_track::switch_template const &Shape, double const Angle) const;
|
|
// the cursor where it points at the straight, at the height of the straight there
|
|
glm::dvec3 cursor_on_straight(editor_track::straight const &Line) const;
|
|
bool insert_double_slip(editor_track::straight const &Line, glm::dvec3 const &Point, editor_track::switch_template const &Shape, int const Side = 0);
|
|
// the side a slip dragged out on a straight with no track crossing it brings its crossing track to: the one through the quarter of
|
|
// the cursor
|
|
int lone_slip_side() const;
|
|
bool replace_double_slip(TTrack &Part, editor_track::switch_template const &Shape);
|
|
// Bend: what a path of the slip laid out as on straights turns into where it's bent into a curve
|
|
std::vector<TTrack *> build_double_slip(glm::dvec3 const &PointA, glm::dvec3 const &PointB, glm::dvec3 const &PointC, glm::dvec3 const &PointD, glm::dvec2 const &Crossing, double const Height, glm::dvec2 const &First, glm::dvec2 const &Second, double const Angle, editor_track::slip_curve const &Curve, TTrack &Style, std::string const &Type = "Rkpd",
|
|
std::function<segment_data(segment_data const &)> const &Bend = {});
|
|
// a slip switch bent into a curve of a side track (ST-T1-A6 11.4 pkt 4b): laid out on the tangent to the curve at its crossing, where
|
|
// it was pressed, and bent onto the curve as a switch laid into it is, its crossing track coming along with its ends free. Direction
|
|
// and Side as of a switch dragged into a curve: the crossing track goes ahead to that side, through the quarter of the cursor, and the
|
|
// slip curve of a single slip lies on that side
|
|
struct curved_slip
|
|
{
|
|
std::string problem;
|
|
std::string snapped; // what the ends of the slip were drawn to
|
|
double middle{0.0}; // the station of the crossing along the curve
|
|
double half{0.0}; // from the crossing to the ends of the slip
|
|
double reach{0.0}; // from the crossing to the joints of the template, the straights of both tracks laid out that far
|
|
int direction{1};
|
|
double angle{0.0};
|
|
editor_track::slip_curve curve;
|
|
// as the slip is laid out on the tangent, before it's bent: its crossing, its tracks going Direction along the curve, its ends
|
|
glm::dvec2 crossing{0.0};
|
|
glm::dvec2 first{0.0, 1.0};
|
|
glm::dvec2 second{0.0, 1.0};
|
|
std::array<glm::dvec3, 4> points{};
|
|
};
|
|
bool plan_curved_slip(editor_track::switch_template const &Shape, int const Direction, int const Side, curved_slip &Plan) const;
|
|
// the path of the slip laid out on the tangent, bent onto the curve
|
|
segment_data bent_slip_path(curved_slip const &Plan, segment_data const &Path) const;
|
|
// the two tracks through the slip and its slip curves, each from end to end, bent: the first track, the slip curve leaving it at its
|
|
// start, the second track, the other slip curve of a double slip
|
|
std::vector<segment_data> curved_slip_lines(curved_slip const &Plan, std::string const &Type) const;
|
|
// the straights of both tracks from the ends of the slip out to the joints of the template, bent
|
|
std::vector<segment_data> curved_slip_reaches(curved_slip const &Plan) const;
|
|
switch_curve::slip_report curved_slip_report(curved_slip const &Plan, std::string const &Type) const;
|
|
// the radii of the slip and its cant, as the view and the status tell them
|
|
static std::vector<std::string> slip_report_lines(switch_curve::slip_report const &Report);
|
|
void insert_curved_slip(int const Direction, int const Side);
|
|
bool start_extend(editor_track::snap_target const &End);
|
|
void finish_extend();
|
|
std::vector<segment_data> extend_pieces() const;
|
|
// the same for the track shown while it's dragged: its grade line fitted on the thread of the fitter, the frame not waiting for it
|
|
std::vector<segment_data> extend_preview() const;
|
|
// the free end of the path as the start of a new track; false if it isn't free or has no direction
|
|
static bool free_end(TTrack &Track, int const Path, bool const Atend, extend_tool &Tool);
|
|
// the free end new pieces are added at: the selected point if it's one, else the end, else the start
|
|
bool chosen_free_end(extend_tool &Tool);
|
|
// adds a straight (Side 0) or a curve to the left (1) or the right (-1) at the free end of the selected track
|
|
void extend_add(int const Side);
|
|
void render_extend_ui();
|
|
using track_layout = editor_track::layout;
|
|
// the shape dragged from a free end, as the mode of laying has it: a straight in the one of the straights, an arc and a straight in
|
|
// the one of a curve
|
|
track_layout m_track_layout{track_layout::straight};
|
|
double m_join_radius{0.0};
|
|
int m_join_variant{0};
|
|
TTrack const *m_join_track{nullptr};
|
|
editor_track::point_ref m_join_point;
|
|
mutable alignment::join_result m_join_last;
|
|
// the layout laid on from the end of From with the transition curves of the norms; none where it doesn't fit
|
|
std::optional<alignment::lay_result> eased_layout(TTrack const *From, glm::dvec3 const &Point, glm::dvec2 const &Direction, glm::dvec3 const &Target, double const Radius) const;
|
|
mutable std::optional<alignment::lay_result> m_eased_last;
|
|
mutable std::optional<std::pair<alignment::lay_request, std::optional<alignment::lay_result>>> m_eased_cache;
|
|
bool track_wheel(double const Offset);
|
|
// a touchpad sends fractions of a notch: a choice moves a step for each whole notch gathered, and only one in a gesture when
|
|
// Gesture; a pause, another key or the other way starts over
|
|
struct wheel_state
|
|
{
|
|
double rest{0.0};
|
|
double time{-10.0};
|
|
int keys{0};
|
|
bool spent{false};
|
|
};
|
|
wheel_state m_wheel;
|
|
int wheel_step(double const Offset, bool const Gesture);
|
|
std::string track_shaping(bool const Joined) const;
|
|
double design_speed(TTrack const *From, TTrack const *To) const;
|
|
// the track whose speed the design takes, none where it's the one set for the laying
|
|
TTrack const *speed_track(TTrack const *From, TTrack const *To) const;
|
|
// the tracks the laying under way goes on from and to
|
|
std::pair<TTrack const *, TTrack const *> laying_ends() const;
|
|
std::string design_speed_of(TTrack const *From, TTrack const *To) const;
|
|
// what ST-T1-A6 says of the sudden changes of the cant deficiency right behind a switch the pieces laid come out of at Start (From),
|
|
// or go into at End (To): of the end of its curve and the first sudden change of the pieces (9.11, tables 9.15, 9.16)
|
|
std::vector<std::string> switch_exit_warnings(TTrack const *From, glm::dvec3 const &Start, TTrack const *To, glm::dvec3 const &End, std::vector<segment_data> const &Pieces) const;
|
|
void give_own_speed(std::vector<TTrack *> const &Created) const;
|
|
std::vector<segment_data> join_pieces(TTrack const *From, editor_track::point_ref const &Frompoint, glm::dvec3 const &Start, glm::dvec2 const &Direction, editor_track::snap_target const &End, double &Length,
|
|
std::string &Error) const;
|
|
double m_extend_length{25.0};
|
|
double m_extend_radius{300.0};
|
|
bool extend_snap(editor_track::snap_target &Target) const;
|
|
void update_build_tools();
|
|
void draw_build_overlay() const;
|
|
// the joint before the blades of the switch being placed or the one selected and the tips of its blades
|
|
void draw_blade_tips() const;
|
|
// modes of the track editor, one at a time: path is the plain selection
|
|
using track_tab = editor_track_tab;
|
|
struct track_mode
|
|
{
|
|
char const *label;
|
|
char const *key;
|
|
track_tab tab;
|
|
char const *tooltip;
|
|
editor_icons::icon picture;
|
|
int family; // 0 builds the track, 1 equips it, 2 checks it
|
|
};
|
|
static std::array<track_mode, 15> const &track_modes();
|
|
bool track_plan_tab() const { return m_track_tab == track_tab::straights || m_track_tab == track_tab::route; }
|
|
// a tool of the station: they share its schematic
|
|
bool srk_tab() const { return m_track_tab == track_tab::station || m_track_tab == track_tab::station_signals || m_track_tab == track_tab::line_block; }
|
|
track_tab plan_tab_for(TTrack const *Track) const;
|
|
// the objects along the track: a tab for each tool
|
|
int m_lineside_tab{0};
|
|
void render_lineside_ui();
|
|
void arm_switch();
|
|
// the window of the switch templates: the catalogue and the own ones, made of straights, arcs and transition curves
|
|
struct switch_designer
|
|
{
|
|
bool open{false};
|
|
bool loaded{false};
|
|
std::vector<switch_design::design> catalogue;
|
|
std::vector<switch_design::design> own;
|
|
bool from_catalogue{true};
|
|
int selected{-1};
|
|
bool dirty{false};
|
|
bool stretched{true};
|
|
double quick_radius{300.0};
|
|
double quick_ratio{9.0};
|
|
double quick_a{0.0};
|
|
double quick_b{0.0};
|
|
int fit_kind{3}; // of switch_design::tangent_fit
|
|
double quick_first{0.0}; // the radius of the first arc of an arc, a straight and an arc, 0: the R
|
|
bool picking{false}; // the switch clicked off the view, the orthophoto under it
|
|
std::vector<glm::dvec3> clicks;
|
|
bool on_view{true}; // the template shown in the view where its first points were clicked
|
|
switch_design::design measured; // what the points clicked so far make
|
|
bool measured_ready{false};
|
|
std::string measured_text;
|
|
int pointed{-1}; // the value under the mouse, its dimension shown on the drawing
|
|
int pointed_test{-1};
|
|
double blade_length{5.0};
|
|
double blade_gap{0.15};
|
|
std::string status;
|
|
};
|
|
switch_designer m_switch_designer;
|
|
void switch_designs_load();
|
|
// the list of the switch tool built again with the own templates, keeping the armed one or arming the one whose label starts with Arm
|
|
void switch_templates_refresh(std::string const &Arm = {});
|
|
void render_switch_designer();
|
|
void switch_designer_click(glm::dvec3 const &Point);
|
|
void switch_designer_measure();
|
|
void switch_designer_finish();
|
|
void draw_switch_designer_clicks() const;
|
|
void draw_cursor_ring(glm::dvec3 const &Point) const;
|
|
static std::string grade_line_key(TTrack const &Track);
|
|
static std::string grade_line_key(std::string const &Name, TTrack const &Track);
|
|
static void move_path_heights(segment_data &Path, double const First, double const Second, std::function<void(segment_data &)> const &After = {});
|
|
bool m_track_window_open{false};
|
|
// the inspector is pinned to the right edge of the screen, the profile strip to the bottom one, both resized from the inner edge
|
|
void render_track_inspector();
|
|
// the track tools in the tool options window, and the selected path in the inspector
|
|
void render_track_tool_options();
|
|
void render_track_selection();
|
|
void show_track_tab(track_tab const Wanted) override;
|
|
bool track_analysis_tab() const { return m_track_tab == track_tab::profile || m_track_tab == track_tab::speed || m_track_tab == track_tab::joints || m_track_tab == track_tab::infra; }
|
|
bool track_shortcut(int const Key);
|
|
bool track_busy() const; // something going on in the mode, which Esc drops before it leaves the mode
|
|
std::string track_mode_name() const;
|
|
void render_turnout_ui();
|
|
struct track_name_edit
|
|
{
|
|
TTrack const *track{nullptr};
|
|
std::string synced;
|
|
char text[128]{};
|
|
editor_track::name_uses uses;
|
|
std::string status;
|
|
};
|
|
track_name_edit m_track_name;
|
|
void render_track_name(TTrack &Track);
|
|
void render_straight_ui();
|
|
track_tab m_track_tab{track_tab::path};
|
|
void delete_selected_track();
|
|
// the switch thrown over to its other path in the editor, its blades going over as in the simulation; the scenery keeps no state of it
|
|
void throw_switch(TTrack &Switch);
|
|
// the blades of the switches thrown in the editor moved on by the time of the frame: the time of the simulation stands still in it
|
|
void move_thrown_switches();
|
|
std::vector<TTrack *> m_thrown_switches;
|
|
std::string designs_trimmed(std::vector<TTrack *> const &Removed);
|
|
void start_straight_gesture(int const Tool);
|
|
void finish_straight_gesture();
|
|
void toggle_straight_set(TTrack &Track);
|
|
struct key_hint
|
|
{
|
|
char const *key;
|
|
std::string action;
|
|
char const *raw{nullptr}; // the key before it's translated, its gesture drawn from it
|
|
};
|
|
std::vector<key_hint> track_key_hints(bool const All) const;
|
|
void render_track_guide();
|
|
std::string track_readout() const;
|
|
void draw_track_hints();
|
|
// a scenery with no tracks yet: in the middle of the view, how the first one is laid
|
|
void draw_empty_scenery_hint();
|
|
// path under the cursor, outlined before a click so it's known which one the click takes
|
|
track_hover m_hover;
|
|
track_hover track_under_cursor(TTrack const *Only = nullptr, float const Pixels = 0.0f) const;
|
|
track_hover split_spot() const;
|
|
void update_track_hover();
|
|
void draw_track_lines() const;
|
|
// what the colours of the tracks in the view tell
|
|
enum class track_colouring { plain, radius, speed, grade };
|
|
track_colouring m_track_colouring{track_colouring::plain};
|
|
void draw_track_legend() const;
|
|
// the radii and lengths of the curves and the names and types of the switches written by them, from above, as on a plan
|
|
bool m_track_labels{true};
|
|
void draw_track_labels() const;
|
|
void draw_track_hover() const;
|
|
struct track_intent
|
|
{
|
|
enum class kind { none, gizmo, select, point, box, straight_set, straight_break, detour, straight_tool, straight_handle, route_vertex, route_grip, switch_at, switch_free, lay, lay_end, sweep, turntable_place, turntable_exit, turntable_fit, spread, extend_end, signal_place, signal_move, signal_read, switch_slide, pick_style, grade_line_pick, fouling, measure, route_trace, kilometrage, srk_boundary, srk_joint };
|
|
kind what{kind::none};
|
|
TTrack *track{nullptr};
|
|
int path{0};
|
|
editor_track::point_ref point;
|
|
int index{-1};
|
|
glm::dvec3 position{0.0};
|
|
editor_track::snap_target snap;
|
|
std::string action;
|
|
};
|
|
track_intent m_intent;
|
|
// the measure between two points (M): on the ground, at a free end or on the axis of the track under the cursor
|
|
struct tape_state
|
|
{
|
|
bool active{false};
|
|
std::vector<glm::dvec3> points;
|
|
glm::dvec3 mouse{0.0};
|
|
};
|
|
tape_state m_tape;
|
|
void tape_update();
|
|
std::string tape_readout() const;
|
|
void draw_tape() const;
|
|
track_intent track_intent_at(int const Mods);
|
|
bool track_gesture_on() const;
|
|
void update_track_intent();
|
|
void track_press(track_intent const &Intent);
|
|
void turntable_press(track_intent const &Intent);
|
|
track_intent turntable_intent(glm::dvec3 const &Ground, bool const Shift);
|
|
void draw_track_intent() const;
|
|
editor_track::snap_target snap_free_end(glm::dvec3 const &Near, glm::vec2 const &Screen, TTrack const *Self, int const Category, std::vector<TTrack const *> const &Exclude) const;
|
|
void draw_free_ends(TTrack const *Self, int const Category, std::vector<TTrack const *> const &Exclude) const;
|
|
// the free ends of the rail tracks around the camera, looked for again after an edit or once the camera leaves the place
|
|
struct free_end_cache
|
|
{
|
|
int edits{-1};
|
|
glm::dvec3 centre{0.0};
|
|
double reach{0.0};
|
|
std::vector<glm::dvec3> points;
|
|
};
|
|
mutable free_end_cache m_free_end_cache;
|
|
std::vector<glm::dvec3> const &free_end_points(glm::dvec3 const &Centre, double const Reach) const;
|
|
struct point_drag
|
|
{
|
|
bool active{false};
|
|
bool moved{false};
|
|
glm::vec2 from{0.f};
|
|
double height{0.0};
|
|
std::size_t step{0};
|
|
};
|
|
point_drag m_point_drag;
|
|
struct handle_drag
|
|
{
|
|
bool active{false};
|
|
bool moved{false};
|
|
glm::vec2 from{0.f};
|
|
double height{0.0};
|
|
glm::dvec3 offset{0.0};
|
|
glm::dvec3 position{0.0};
|
|
};
|
|
handle_drag m_handle_drag;
|
|
void handle_drag_start(glm::dvec3 const &Anchor);
|
|
// Ground: the handle goes onto the ground, at the height of the ballast of the track, unless Shift is held
|
|
bool handle_drag_step(glm::dvec3 &Position, TTrack const *Ground = nullptr);
|
|
void point_drag_start(editor_track::point_ref const &Point);
|
|
void point_drag_update();
|
|
void point_drag_finish();
|
|
bool route_hit(int &Vertex, int &Grip) const;
|
|
int straight_handle_hit();
|
|
bool switch_reach(glm::dvec3 const &Ground, glm::dvec3 &Point);
|
|
glm::dvec3 cursor_ground() const;
|
|
glm::dvec3 cursor_level(double const Height) const;
|
|
glm::dvec3 cursor_terrain(double const Height);
|
|
double bed_height(glm::dvec3 const &Point, glm::dvec2 const &Direction, TTrack const *Style) const;
|
|
double nearby_ground(glm::dvec3 const &Point) const;
|
|
static std::pair<double, double> trackbed(TTrack const *Style);
|
|
std::vector<double> bed_heights(std::vector<glm::dvec3> const &Points, std::vector<glm::dvec2> const &Directions, TTrack const *Style) const;
|
|
void follow_ground(std::vector<segment_data> &Pieces, double const Height0, double const Grade0, double const Height1, double const Grade1, TTrack const *Style) const;
|
|
ground_follow::grading laying_grading(TTrack const *Style) const;
|
|
// the grade lines of the tracks shown while they're laid are fitted on a thread of their own, not to hold up the frames
|
|
mutable ground_follow::fitter m_fitter;
|
|
mutable bool m_follow_preview{false};
|
|
glm::dvec3 lay_bed(glm::dvec3 const &Point);
|
|
std::optional<glm::dvec3> m_cursor_override;
|
|
bool sweep_grabs(glm::dvec3 const &Point);
|
|
// menu of the path a click of the right mouse button lands on
|
|
struct track_context
|
|
{
|
|
track_hover target;
|
|
std::chrono::steady_clock::time_point pressed;
|
|
glm::vec3 angle{0.f};
|
|
glm::vec2 mouse{0.f};
|
|
bool armed{false};
|
|
bool pending{false};
|
|
};
|
|
track_context m_track_context;
|
|
void track_context_press();
|
|
void track_context_release();
|
|
void render_track_context();
|
|
void split_track_at(TTrack &Track, glm::dvec3 const &Point);
|
|
void focus_track(TTrack &Track, int const Path, glm::dvec3 const &Point) override;
|
|
// the camera flies over Duration seconds to the place Distance back from the target along Look, looking along it
|
|
void fly_to(glm::dvec3 const &Target, glm::dvec3 const &Look, double const Distance, double const Duration = 0.6) override;
|
|
// paths found by their names
|
|
struct track_search
|
|
{
|
|
char text[64]{};
|
|
std::string searched;
|
|
std::vector<TTrack *> found;
|
|
std::size_t total{0};
|
|
bool focus{false};
|
|
};
|
|
track_search m_track_search;
|
|
void render_track_search();
|
|
// paths selected together: Shift+LMB adds or takes one out, Shift+drag adds those in the box
|
|
std::vector<TTrack *> m_track_set;
|
|
struct track_box
|
|
{
|
|
bool active{false};
|
|
bool replace{false}; // the tracks in the box become the selection, else they join it
|
|
glm::vec2 from{0.f};
|
|
glm::vec2 to{0.f};
|
|
TTrack *hovered{nullptr};
|
|
};
|
|
track_box m_track_box;
|
|
glm::mat4 m_track_set_gizmo{1.0f};
|
|
bool m_track_set_using{false};
|
|
glm::dvec3 m_track_set_pivot{0.0};
|
|
std::vector<std::pair<TTrack *, std::vector<editor_track::joint>>> m_track_set_joints;
|
|
bool in_track_set(TTrack const *Track) const;
|
|
// the track is selected: alone or in the set
|
|
bool track_selected(TTrack const *Track) const;
|
|
// a click in the view: the track under the cursor becomes the selection, or nothing
|
|
void track_click_select(TTrack *Hovered);
|
|
bool track_set_begin(bool const Rotate);
|
|
void track_set_turn(double const Angle);
|
|
void track_set_move(glm::dvec3 const &Offset);
|
|
void track_set_end();
|
|
glm::dvec3 track_set_centre() const;
|
|
void track_set_toggle(TTrack &Track);
|
|
void track_set_prune();
|
|
void start_track_box(bool const Replace = false);
|
|
void finish_track_box();
|
|
void draw_track_set() const;
|
|
void render_track_set_ui();
|
|
void render_track_set_gizmo();
|
|
void track_set_delete();
|
|
struct track_spread
|
|
{
|
|
int stop{0};
|
|
bool same_rails{false};
|
|
bool same_bed{false};
|
|
bool same_speed{false};
|
|
float reach{0.f};
|
|
TTrack const *from{nullptr};
|
|
int signature{-1};
|
|
std::vector<TTrack *> preview;
|
|
double length{0.0};
|
|
};
|
|
mutable track_spread m_spread;
|
|
std::vector<TTrack *> track_spread_from(TTrack &Start) const;
|
|
std::vector<TTrack *> const &track_spread_preview(TTrack &Start) const;
|
|
void track_spread_apply(TTrack &Start);
|
|
void track_set_grow();
|
|
void render_track_spread_ui();
|
|
void draw_track_spread() const;
|
|
// the properties of the selected tracks in the inspector, one sheet for one track and for many; see editormodetrackprops.cpp
|
|
// the set when there's one, the selected track otherwise
|
|
std::vector<TTrack *> selected_tracks();
|
|
void select_tracks(std::vector<TTrack *> const &Tracks);
|
|
// changes each track which can be changed, in one step of the undo; false from Change: the track stays as it was
|
|
std::size_t tracks_apply(std::vector<TTrack *> const &Tracks, std::function<bool(TTrack &)> const &Change, bool const Rebuild, char const *What);
|
|
// the model of the timbers, with the fastenings where it has them, set on all the switches and crossings of the scenery, in one
|
|
// step of the undo; empty: the one of eu07.ini. returns: the tracks changed
|
|
std::size_t set_switch_timbers(std::string const &Model);
|
|
int track_property_index(std::string const &Key) const;
|
|
std::size_t track_property_apply(int const Property, std::vector<TTrack *> const &Tracks, std::string const &Text);
|
|
void track_field_finish();
|
|
void track_field_settle();
|
|
void track_textures_scan();
|
|
// a texture in use, offered first in the picker
|
|
struct texture_use
|
|
{
|
|
material_handle material{null_handle}; // null: its image is read by the name
|
|
std::string name;
|
|
int count{0}; // shown on its tile, 0: nothing
|
|
std::string note; // what's said of it above the tiles
|
|
};
|
|
// what the picker of a texture offers besides every texture of the folder
|
|
struct texture_offer
|
|
{
|
|
char const *title; // the heading of the ones in use
|
|
std::function<std::vector<texture_use>()> used; // gathered when the picker opens
|
|
char const *none; // the entry for no texture, nullptr: there's none
|
|
char const *none_name; // the name that entry gives
|
|
};
|
|
// every texture and material under the folder of the textures, read on the first use of the picker
|
|
void textures_index();
|
|
// the picker of a texture, in an open combo. returns: true when one is chosen, its name in Chosen
|
|
bool texture_picker(texture_offer const &Offer, std::string const &Current, bool const Mixed, std::string &Chosen);
|
|
// the same, of a texture of the rails (Kind 0) or of the trackbed (1)
|
|
bool track_texture_picker(int const Kind, std::string const &Current, bool const Mixed, std::string &Chosen);
|
|
// image of the texture of the name, 0 while there's none
|
|
std::uint64_t texture_image(std::vector<texture_use> const &Used, std::string const &Name);
|
|
std::uint64_t track_texture_image(int const Kind, std::string const &Name);
|
|
// a field of a texture: its image and its name, a click opens the picker, a material of the texture browser can be dropped on it.
|
|
// returns: true when another one was chosen, in Value
|
|
bool texture_field(char const *Label, float const Width, std::string &Value, texture_offer const &Offer);
|
|
// the same, for a name kept in a buffer
|
|
bool texture_field(char const *Label, float const Width, char *Buffer, std::size_t const Size, texture_offer const &Offer);
|
|
// the textures of the roads and junctions of the scenery
|
|
std::vector<texture_use> road_textures_used() const;
|
|
// the textures of the palette and of the water of the terrain; None: the entry for no texture of its own, nullptr: there's none
|
|
texture_offer terrain_texture_offer(char const *None);
|
|
void render_track_properties(std::vector<TTrack *> const &Tracks);
|
|
void render_track_set_header(std::vector<TTrack *> const &Tracks);
|
|
void render_track_select_tools(std::vector<TTrack *> const &Tracks);
|
|
void render_track_style(std::vector<TTrack *> const &Tracks);
|
|
void copy_track_style(TTrack const &Track);
|
|
std::size_t paste_track_style(std::vector<TTrack *> const &Tracks);
|
|
// which groups of the properties are pasted or put on the tracks by a preset, in the order of the groups of editormodetrackprops.cpp
|
|
using track_groups = std::array<bool, 11>;
|
|
// the values of the properties of the chosen groups put on the tracks, in one step of the undo. returns: the number of the
|
|
// tracks changed, none when no value is of the chosen groups
|
|
std::optional<std::size_t> apply_track_values(std::vector<std::pair<std::string, std::string>> const &Values, track_groups const &Groups, std::vector<TTrack *> const &Tracks, char const *What);
|
|
// presets of the properties of the tracks (editorTrackPresets), made from a track and put on the selected ones
|
|
void render_track_presets(std::vector<TTrack *> const &Tracks);
|
|
void render_track_presets_menu();
|
|
std::size_t apply_track_preset(int const Id, std::vector<TTrack *> const &Tracks);
|
|
std::vector<TTrack *> similar_tracks(int const Property, std::vector<TTrack *> const &Tracks) const;
|
|
// values of the properties over the selected tracks, each with the number of the tracks having it
|
|
struct track_values
|
|
{
|
|
std::size_t signature{0};
|
|
int generation{0};
|
|
int generation_seen{-1};
|
|
std::size_t history{0};
|
|
int frame{-100};
|
|
std::vector<std::vector<std::pair<std::string, int>>> values;
|
|
std::vector<std::size_t> applies;
|
|
std::size_t unsaved{0}; // of the tracks, changed since the file was written
|
|
};
|
|
track_values m_track_values;
|
|
// how the last value given in the sheet went: on how many tracks, and why not on the others
|
|
struct track_outcome
|
|
{
|
|
int property{-1};
|
|
std::string text;
|
|
bool refused{false}; // some tracks couldn't take it
|
|
std::size_t signature{0}; // of the tracks it was given to
|
|
std::size_t history{0};
|
|
double time{0.0};
|
|
};
|
|
track_outcome m_track_outcome;
|
|
// the lines under the rows of the sheet
|
|
struct track_note
|
|
{
|
|
enum class kind
|
|
{
|
|
typing,
|
|
done,
|
|
refused
|
|
};
|
|
int property{-1};
|
|
std::string text;
|
|
kind type{kind::done};
|
|
};
|
|
std::vector<track_note> m_track_notes;
|
|
// the field being typed in, with the tracks it was started on
|
|
struct track_field
|
|
{
|
|
int property{-1};
|
|
std::vector<TTrack *> tracks;
|
|
std::array<char, 256> text{};
|
|
std::string initial;
|
|
int frame{0};
|
|
};
|
|
track_field m_track_field;
|
|
std::array<std::vector<texture_use>, 2> m_track_textures; // of the rails, of the trackbed
|
|
std::vector<texture_use> m_texture_used; // the ones in use the open picker offers
|
|
std::array<char, 128> m_texture_filter{};
|
|
struct texture_index_entry
|
|
{
|
|
std::string name; // as the materials are named: relative to the folder of the textures, without the extension
|
|
std::string lowered;
|
|
bool material{false}; // there's a .mat file of the name
|
|
};
|
|
std::vector<texture_index_entry> m_texture_index; // sorted by the name
|
|
bool m_texture_indexed{false};
|
|
std::string m_texture_hovered; // the tile under the mouse in the picker, shown large above them
|
|
// properties taken from a track, to be set on the selected ones
|
|
struct track_style
|
|
{
|
|
std::string from;
|
|
std::vector<std::pair<std::string, std::string>> values;
|
|
// ticked at first by their groups: speed, environment, overhead line, track circuits, rails, trackbed, its shape, sleepers, ride and
|
|
// sound, frogs, sleeper placement
|
|
track_groups groups{false, false, false, false, true, true, true, true, false, true, true};
|
|
std::map<std::string, bool> ticks; // changed by hand, by the keys of the properties
|
|
bool picking{false}; // the next click on a track in the view takes its properties
|
|
bool reveal{false}; // its section of the inspector opens, a track having been taken
|
|
};
|
|
track_style m_track_style;
|
|
// a property of the track taken which the selected ones have otherwise
|
|
struct track_style_line
|
|
{
|
|
int property{-1};
|
|
std::string now; // as the selected tracks have it, or how many values they have
|
|
std::string taken; // as the track taken has it
|
|
std::size_t differ{0}; // of the selected tracks, the ones it changes
|
|
};
|
|
std::vector<track_style_line> track_style_lines(std::vector<TTrack *> const &Tracks);
|
|
bool track_style_takes(std::string const &Key) const;
|
|
struct track_presets_panel
|
|
{
|
|
int selected{0}; // id of the preset chosen in the inspector
|
|
int nameid{0}; // the preset whose name is in the field
|
|
char name[128]{};
|
|
};
|
|
track_presets_panel m_track_presets;
|
|
std::vector<std::vector<TTrack *>> m_track_similar;
|
|
TTrack const *m_track_list_hover{nullptr}; // in the list of the selected tracks
|
|
int m_track_list_hover_frame{-1};
|
|
using template_item = ::template_item;
|
|
using standing_template = ::standing_template;
|
|
// includes of the templates whose file names the test accepts, with the location in p2..p4 and the rotation in p5
|
|
std::vector<standing_template> standing_templates(std::function<bool(std::string const &)> const &Accept) const override;
|
|
struct switch_drive
|
|
{
|
|
standing_template standing;
|
|
int family{-1}; // -1: a drive not described for the editor, e.g. of Rainsted; it can be replaced, not turned over or moved
|
|
int index{-1};
|
|
};
|
|
std::optional<switch_drive> find_switch_drive(TTrack const &Switch, bool Wait = true);
|
|
// the drives standing in the scenery by the switch each is set to, read from the files once a frame for all the switches
|
|
std::map<std::string, switch_drive> const &switch_drives_standing(bool Wait = true);
|
|
struct drives_standing
|
|
{
|
|
std::map<std::string, switch_drive> by_switch;
|
|
int frame{-1};
|
|
int revision{-1}; // of the drives scanned
|
|
std::size_t instances{0};
|
|
};
|
|
std::optional<drives_standing> m_drives_standing; // emptied when an include changes
|
|
std::string missing_drive_variant(int const Family, bool const Rightswitch, bool const Driveright) const;
|
|
bool replace_switch_drive(TTrack &Switch, int Family, bool Flip);
|
|
void apply_switch_drive_choice(TTrack &Switch);
|
|
void switch_drive_captured(TTrack const &Track);
|
|
void switch_drives_committed(std::vector<TTrack *> const &Tracks);
|
|
// the drives of the switches deleted go with them, in the step of the undo history the deletion made last
|
|
void drives_deleted(std::vector<TTrack *> const &Switches);
|
|
// the file of a drive not described for the editor throwing one of the switches, empty when there's none; also one the editor
|
|
// kept beside a drive described for it
|
|
std::string undescribed_drive(std::vector<TTrack *> const &Switches);
|
|
// the drives of all the switches of the scenery set at the tips of their blades, the ones the earlier versions of the editor set at the
|
|
// joint before them too: once, as the scenery is opened, with no step of the undo history; how many moved
|
|
std::size_t drives_to_blade_tips();
|
|
bool m_drives_checked{false};
|
|
// the file of each variant of the drives scanned: its family and its index in the family
|
|
std::map<std::string, std::pair<int, int>, std::less<>> drive_variants() const;
|
|
// the switches a template of a drive throws, by what follows its first parameter in their names: "" for a variant described for the
|
|
// editor, and for any other template whose switch events throw the track named by its first parameter, as the drives of Rainsted do;
|
|
// "a".."d" for one of a double switch, whose switches are named <name>a..<name>d. none for a template which isn't a drive. the ones not
|
|
// described for the editor have no family (-1)
|
|
std::vector<std::string> const &drive_switches(std::string const &File, std::map<std::string, std::pair<int, int>, std::less<>> const &Variants);
|
|
std::map<std::string, std::vector<std::string>, std::less<>> m_drive_templates; // read once for each file
|
|
// a drive set to a switch the scenery hasn't got: left by a switch deleted or renamed by hand or in an earlier editor, its events
|
|
// throw nothing
|
|
struct stray_drive
|
|
{
|
|
scene::instance_handle instance{0};
|
|
std::vector<std::string> switches; // the names of the switches it throws, as its include gives them
|
|
std::string name; // of the switches missing from them
|
|
std::string file;
|
|
glm::dvec3 location{0.0};
|
|
};
|
|
// all the drives standing in the scenery, read from the files once while no include comes or goes
|
|
struct drives_named
|
|
{
|
|
std::vector<stray_drive> drives;
|
|
int revision{-1}; // of the drives scanned
|
|
std::size_t instances{0};
|
|
};
|
|
std::optional<drives_named> m_drives_named;
|
|
// the include of a drive or a template changed: what's kept of the drives standing is read again
|
|
void drives_changed();
|
|
// the drives whose switch isn't in the scenery, checked against the tracks each time
|
|
std::vector<stray_drive> stray_drives(bool Wait = false);
|
|
void render_stray_drives();
|
|
void draw_stray_drives();
|
|
scene::layer_handle output_layer(std::string const &Part) override;
|
|
// places them in the active layer or the given one, as one step of the undo. returns: how many were placed
|
|
std::size_t place_templates(std::vector<template_item> const &Items, std::string &Error, scene::layer_handle Layer = scene::layer_handle{}) override;
|
|
// moves them, as one step of the undo
|
|
std::size_t move_templates(std::vector<std::pair<standing_template, template_item>> const &Moves) override;
|
|
// takes them out, as one step of the undo
|
|
std::size_t remove_templates(std::vector<scene::instance_handle> const &Instances) override;
|
|
bool standing_signals(std::vector<standing_signal> &Signals, bool const Wait) override;
|
|
std::size_t signal_batch(signal_changes const &Changes, std::vector<std::pair<TTrack *, editor_track::state>> States, std::vector<TTrack *> Created, std::string &Error) override;
|
|
std::string signal_templates_missing(std::vector<signal_order> const &Orders) override;
|
|
bool signal_heads(std::vector<signal_head> &Heads, bool const Wait) override;
|
|
std::string signal_mount(std::string const &Kind, std::string const &File) override;
|
|
std::size_t signal_reattach(std::vector<scene::instance_handle> const &Instances) override;
|
|
void select_signal(scene::instance_handle const Instance) override;
|
|
void render_signal_templates(std::vector<std::string> const &Kinds) override;
|
|
|
|
struct signal_template
|
|
{
|
|
std::string file;
|
|
std::string name;
|
|
std::string description;
|
|
std::string kind;
|
|
std::string mount;
|
|
std::string lamps;
|
|
std::string lean;
|
|
std::string read;
|
|
int parameters{0};
|
|
bool plate{false};
|
|
bool linked{false};
|
|
std::vector<int> speeds;
|
|
int aspects{0}; // of a block signal, 3 or 4
|
|
int arms{0}; // of a semaphore, 1 or 2, from its description
|
|
// m, of the zero of its model over the rail heads, from its description: where it stands by default
|
|
double height{0.0};
|
|
// m, how deep its model reaches under its zero, from its description: none, it isn't put on the ground
|
|
std::optional<double> depth;
|
|
// the aspects its description lists, by name (Sr1, Od2...) with the event giving each; empty for a template not described so
|
|
std::vector<std::pair<std::string, std::string>> aspect_events;
|
|
// of a warning disc: its event for each speed class of the signal after it, stop, vmax, 100, 60, 40
|
|
std::vector<std::pair<std::string, std::string>> repeats;
|
|
};
|
|
// an indicator to put on a signal, a template described as one
|
|
struct indicator_template
|
|
{
|
|
std::string file;
|
|
std::string name;
|
|
std::string description;
|
|
std::string sign;
|
|
std::string place; // "head": under the lights of the signal, one under another; "foot": by its foot, the place in its model
|
|
std::vector<std::pair<std::string, std::string>> events;
|
|
};
|
|
struct signal_spot
|
|
{
|
|
TTrack *track{nullptr};
|
|
int path{0};
|
|
glm::dvec3 axis{0.0};
|
|
glm::dvec2 travel{0.0, 1.0};
|
|
int side{1};
|
|
int list{2};
|
|
double offset{0.0};
|
|
glm::dvec3 position{0.0};
|
|
double yaw{0.0};
|
|
// the path and its list that read the signal: the track it stands by, or past the frog of a switch the track joined to the end
|
|
// of its path, which only the trains of that path run on
|
|
TTrack *reader{nullptr};
|
|
int reader_list{2};
|
|
};
|
|
struct signal_standing
|
|
{
|
|
standing_template include;
|
|
int kind{-1};
|
|
std::string name;
|
|
std::string read;
|
|
TTrack *track{nullptr};
|
|
int list{0};
|
|
// every path and list having the read, the first of them in track and list
|
|
std::vector<std::pair<TTrack *, int>> reads;
|
|
// the indicators put on it: named after it, at its foot, the highest first
|
|
std::vector<standing_template> indicators;
|
|
};
|
|
struct signal_tool
|
|
{
|
|
std::vector<signal_template> templates;
|
|
std::vector<indicator_template> indicators;
|
|
int revision{-1};
|
|
int kind{0};
|
|
std::array<int, 8> chosen{-1, -1, -1, -1, -1, -1, -1, -1};
|
|
bool armed{false}; // a click by a track places the chosen template
|
|
char filter[64]{};
|
|
char name[64]{"A"};
|
|
char plate[64]{};
|
|
std::array<char, 3> plate_index{}; // the speed index of the drawn plate, "4" or "12" for 1/2
|
|
bool plate_m{false}; // the drawn plate gets the "m" of a signal giving shunting signals too
|
|
char linked[64]{"none"};
|
|
float height{0.0f};
|
|
bool placing{false};
|
|
signal_spot press;
|
|
signal_spot press_raw; // where the press was, before it went to a round distance to the switch ahead
|
|
glm::vec2 pressed{0.f};
|
|
int facing{0};
|
|
std::vector<signal_standing> standing;
|
|
std::size_t standing_history{static_cast<std::size_t>(-1)};
|
|
double standing_time{-1.0};
|
|
int hover{-1};
|
|
scene::instance_handle selected{0};
|
|
bool moving{false};
|
|
glm::dvec2 grab{0.0};
|
|
signal_spot home;
|
|
bool home_valid{false};
|
|
signal_spot moved;
|
|
bool moved_valid{false};
|
|
// a click on a track gives the read of the signal selected to it
|
|
bool picking_read{false};
|
|
// the entry of the selected signal into the gauge of the paths around it, measured again as the history or the selection changes
|
|
struct
|
|
{
|
|
scene::instance_handle instance{0};
|
|
std::size_t history{static_cast<std::size_t>(-1)};
|
|
glm::dvec3 location{0.0}; // of the signal, which follows a dragged track without a new step of the history
|
|
gauge_tool::gauge_hit hit;
|
|
} gauge;
|
|
// the signal the gizmo has taken: as it stood then, the frame of its models, the size of the history before the step of the
|
|
// gizmo and the directives of its indicators
|
|
struct
|
|
{
|
|
scene::instance_handle instance{0};
|
|
signal_standing from;
|
|
glm::dmat3 frame{1.0};
|
|
std::size_t history{0};
|
|
std::vector<std::pair<scene::instance_handle, std::string>> directives;
|
|
} gizmo;
|
|
std::string status;
|
|
};
|
|
signal_tool m_signal;
|
|
// the way from the spot of a signal along its track to the switch the trains it faces come to first
|
|
track_trace::danger signal_danger(signal_spot const &Spot) const;
|
|
// the spot moved along its track to a round distance to the switch ahead, 50 m, 100 m..., when it's that near one; Alt leaves it
|
|
void signal_snap(signal_spot &Spot, signal_template const &Template) const;
|
|
// of the selected signal: the spot it stands at and the way to the switch ahead of it, kept until it or the history changes
|
|
struct signal_metre
|
|
{
|
|
scene::instance_handle instance{0};
|
|
std::size_t history{static_cast<std::size_t>(-1)};
|
|
glm::dvec3 location{0.0};
|
|
double yaw{0.0};
|
|
bool valid{false};
|
|
signal_spot spot;
|
|
track_trace::danger danger;
|
|
};
|
|
mutable signal_metre m_signal_metre;
|
|
signal_metre const &signal_metre_of(signal_standing const &Standing) const;
|
|
bool signal_scan(bool Wait = true);
|
|
signal_template const *signal_current() const;
|
|
signal_template const *signal_armed() const;
|
|
signal_template const *signal_template_of(std::string const &File) const;
|
|
// the template it is placed by: the one of its file if that is of its kind, else the one chosen for its kind. returns: nullptr if none
|
|
signal_template const *signal_template_for(signal_order const &Order) const;
|
|
bool signal_spot_at(TTrack &Track, int const Path, glm::dvec3 const &Point, glm::dvec3 const &Cursor, int const Facing, int const Side, signal_template const &Template, signal_spot &Spot) const;
|
|
void signal_refresh(bool const Force = false);
|
|
// the signals standing, read by the tracks as they are now, the templates as found so far
|
|
std::vector<signal_standing> signal_standing_now() const;
|
|
int signal_hit() const;
|
|
void signal_press(track_intent const &Intent);
|
|
void signal_release();
|
|
bool signal_place(signal_spot const &Spot, signal_template const &Template);
|
|
void signal_move_update();
|
|
// Moved: the signal moved from its track, the nearest track takes it if that's nearer by more than a little
|
|
bool signal_standing_spot(signal_standing const &Standing, signal_spot &Spot, bool const Moved = false) const;
|
|
bool signal_drop_at(signal_standing const &Standing, TTrack &Track, int const Path, glm::dvec3 const &Point, int const Side, signal_spot &Spot) const;
|
|
bool signal_move_to(signal_standing const &Standing, signal_spot const &Spot, char const *Read, char const *Unread);
|
|
indicator_template const *indicator_template_of(std::string const &File) const;
|
|
// the indicator put on the signal, named after it: under its lights below the ones there, or at its foot. returns: false if it can't be
|
|
bool signal_indicator_add(signal_standing const &Standing, indicator_template const &Indicator);
|
|
bool signal_indicator_remove(scene::instance_handle const Indicator);
|
|
// the indicators under the lights of the signal at Upper and Lower in its list, the highest first, swapped: each takes the place of the other
|
|
bool signal_indicators_swap(signal_standing const &Standing, std::size_t const Upper, std::size_t const Lower);
|
|
// the signal set the distance from the axis of its track in the plan and its height, raised over where it stands by default (over the rail heads, on a gantry), unless none
|
|
bool signal_set_across(signal_standing const &Standing, std::optional<double> const Offset, std::optional<double> const Height);
|
|
// the distance from the axis and the height over where it stands by default From has, carried to To, a spot of the same signal
|
|
// along its track: a signal set across or raised by hand keeps it as it is dragged or snapped
|
|
void signal_carry(signal_spot const &From, signal_spot &To, signal_template const &Template) const;
|
|
// the height of the zero of the model of a signal at Position by the track of the axis at Axis, as it stands by default: as far over
|
|
// the rail heads as its description gives, lower only where its bottom would hang over the ground; a gantry as high over the rails
|
|
// as chosen
|
|
double signal_default_height(signal_template const &Template, glm::dvec3 const &Axis, glm::dvec3 const &Position) const;
|
|
// how much higher the default height of To is than of From at Position by the track of the axis at Axis: what a signal given the
|
|
// template To in place of From goes up by, to stand as raised as it was
|
|
double signal_default_change(signal_template const &From, signal_template const &To, glm::dvec3 const &Axis, glm::dvec3 const &Position) const;
|
|
// the indicators of the signal moved after it to the place and the frame it has now, at the same place by it as they were, the
|
|
// directives they had going to Directives
|
|
void signal_indicators_follow(signal_standing const &Standing, glm::dmat3 const &Before, std::vector<std::pair<scene::instance_handle, std::string>> &Directives);
|
|
bool render_signal_indicators(signal_standing const &Found);
|
|
// the indicators put on the signal named Name standing at Location, as the scenery has them now, the highest first: the list of
|
|
// the tool is kept up only while the tool is open
|
|
std::vector<standing_template> signal_indicators_of(std::string const &Name, glm::dvec3 const &Location) const;
|
|
// the indicators of the signal named Before at Location named After it, the directives they had going to Directives once each
|
|
void signal_indicators_renamed(std::string const &Before, std::string const &After, glm::dvec3 const &Location, std::vector<std::pair<scene::instance_handle, std::string>> &Directives);
|
|
// the directives of more includes taken back by the step: one of a single include is made one of them
|
|
void history_add_directives(EditorSnapshot &Step, std::vector<std::pair<scene::instance_handle, std::string>> const &Directives);
|
|
// the signal of the selected include taken by the gizmo: its indicators go with it, and once it's let go it is moved as a drag of
|
|
// the signal tool moves it, read by the path it stands by then, out of the gauge, as one step of the history
|
|
void signal_gizmo_begin();
|
|
void signal_gizmo_step();
|
|
void signal_gizmo_end();
|
|
// the height of the lowest lamp of the signal in the world, from the geometry of its lamps; 0 when it has none
|
|
double signal_lowest_lamp(scene::instance_handle const Instance) const;
|
|
// the deepest entry of the models of the signal into the gauge of the paths around it
|
|
gauge_tool::gauge_hit signal_gauge(scene::instance_handle const Instance);
|
|
// the signal just placed or moved, at Local in its file, taken across away from the axis of each path whose gauge it enters, a few
|
|
// times at most, its directive changed with it. returns: the way it went, metres, and in Hit the entry it still makes
|
|
double signal_off_gauge(scene::instance_handle const Instance, std::string const &File, std::vector<std::string> &Values, glm::dvec3 Local, gauge_tool::gauge_hit &Hit);
|
|
// a sentence more to the status about it, none when the signal kept out of the gauge where it was put
|
|
void signal_gauge_note(std::string &Status, double const Shift, gauge_tool::gauge_hit const &Hit, bool const Gantry) const;
|
|
bool signal_flip(scene::instance_handle const Instance);
|
|
bool signal_turn(scene::instance_handle const Instance);
|
|
bool signal_swap(scene::instance_handle const Instance, std::string const &File);
|
|
// the signal set to the aspect in the editor, as its event sets it in the game: only how it looks, nothing saved
|
|
bool signal_show_aspect(scene::instance_handle const Instance, std::string const &Aspect, std::string const &Event);
|
|
signal_standing const *signal_standing_of(scene::instance_handle const Instance) const;
|
|
bool signal_delete(scene::instance_handle const Instance);
|
|
void signal_detach_events(std::string const &Read, std::vector<std::pair<TTrack *, editor_track::state>> &States);
|
|
// a track split in two: the reads of the signals placed since the scenery was opened, not bound yet, go to the piece by the signal
|
|
void signal_split(TTrack &Original, TTrack &Created);
|
|
// the list of a path the trains the signal faces read it from, as they run by the point of the path nearest to it
|
|
int signal_read_list(signal_standing const &Standing, TTrack const &Track, int const Path) const;
|
|
// the read of the signal in exactly these lists of these paths, as one step taken back by Ctrl+Z
|
|
bool signal_read_set(signal_standing const &Standing, std::vector<std::pair<TTrack *, int>> const &Reads);
|
|
// a click on a track while picking the path that reads the selected signal: its read goes there, or one more there with Add,
|
|
// or off it with Add when it's there already
|
|
bool signal_read_pick(TTrack &Track, int const Path, bool const Add);
|
|
std::string signal_read_label(TTrack const &Track, int const Path, bool const Add) const;
|
|
void signal_renamed(std::string const &Before, std::string const &After, EditorSnapshot &Snapshot);
|
|
// the plate a signal of this name gets when none is picked: one drawn by python/local/signal_plate.py with the given style
|
|
// ("look=toned", with "&index=12" and "&m=1" when it has them), or none for a name it can't carry
|
|
static std::string signal_plate(std::string const &Name, std::string const &Style);
|
|
// true for a plate signal_plate() gives, of any name and look
|
|
static bool signal_plate_drawn(std::string_view Plate);
|
|
static bool signal_plate_blank(std::string const &Name, std::string const &Plate);
|
|
static std::string signal_plate_text(std::string const &Name);
|
|
// what a drawn plate is drawn with but its name, kept through a rename; for one not drawn the look set in the editor
|
|
static std::string signal_plate_style(std::string const &Plate);
|
|
void signal_select(scene::instance_handle const Instance);
|
|
std::string signal_next_name(std::string const &Name) const;
|
|
void render_signal_ui();
|
|
void render_signal_palette();
|
|
void render_signal_selected();
|
|
// the paths reading the signal, each turned the other way or removed, a path picked or the one the editor gives. returns: true when they changed
|
|
bool render_signal_reads(signal_standing const &Found);
|
|
// of the signal selected: its template and another one for it, the aspects it can be set to; true when it got another one
|
|
bool render_signal_template(signal_standing const &Found, signal_template const &Item);
|
|
// the list of the templates the signal can take instead, Across those of another mount too: the file picked, empty for none
|
|
std::string signal_swap_combo(signal_template const &Item, bool const Across) const;
|
|
void render_signal_aspects(signal_standing const &Found, signal_template const &Item);
|
|
void draw_signal_overlay() const;
|
|
std::string signal_intent_label(signal_template const &Template, signal_spot const &Spot) const;
|
|
std::string signal_variant(signal_template const &Template, signal_spot const &Spot) const;
|
|
// what a deleted track carried and no other one took, its read events and track circuits, for a track laid in its place
|
|
struct orphan_record
|
|
{
|
|
TTrack *track{nullptr}; // retired; the record waits while it stays so
|
|
std::vector<std::pair<std::string, int>> events; // the name, the list it was on
|
|
std::vector<std::string> circuits;
|
|
// the tracks given the circuits: while one stays the circuits don't wait, once a step other than an undo removes one they
|
|
// are its own
|
|
std::vector<TTrack *> given;
|
|
bool fresh{false}; // made by the step being taken
|
|
};
|
|
std::vector<orphan_record> m_orphans;
|
|
std::string m_orphan_note; // shown by the cursor after the step which made it
|
|
void orphans_register(std::vector<TTrack *> const &Removed, std::vector<TTrack *> const &Kept);
|
|
// Created: made by the step, their circuits the ones of the tracks they were made from; Changed: the others it changed
|
|
void orphans_take_over(std::vector<TTrack *> const &Created, std::vector<TTrack *> const &Changed);
|
|
|
|
// a model laid along the track: bent to follow it, or repeated along it
|
|
struct sweep_tool
|
|
{
|
|
bool open{false};
|
|
bool expand{false};
|
|
char model[256]{};
|
|
char skin[128]{"none"};
|
|
char search[64]{};
|
|
std::vector<std::string> models;
|
|
bool scanned{false};
|
|
int revision{-1}; // of the include bank the templates were taken from
|
|
// parameters of a template laid along the track, with their names
|
|
std::string parameters_for;
|
|
std::vector<std::array<char, 128>> parameters;
|
|
std::vector<std::string> parameter_labels;
|
|
std::vector<bool> parameter_placement; // filled in with zeros: the template is placed in its own space
|
|
std::vector<std::vector<std::string>> parameter_choices; // variants of the textures a parameter is a part of the name of
|
|
int length_mode{2}; // 0: one copy as long as the original, 1: the length given, 2: the whole stretch of the line
|
|
double length{200.0};
|
|
sweep_node::state settings;
|
|
int axis{0}; // 0: the longer one of the model, 1: z, 2: x
|
|
double model_length{0.0};
|
|
std::string measured; // model the length is of
|
|
// the curve: the axis of the track
|
|
TTrack *curve_for{nullptr};
|
|
std::size_t curve_history{0};
|
|
struct piece
|
|
{
|
|
TTrack *track{nullptr};
|
|
int path{0};
|
|
bool forward{true};
|
|
};
|
|
std::vector<piece> curve_pieces;
|
|
std::vector<segment_data> curve;
|
|
double curve_length{0.0};
|
|
std::vector<glm::dvec3> outline; // of the curve, for the preview
|
|
std::vector<double> stations;
|
|
// marking the stretch in the view: press where it starts, the distance from the track sets the offset, drag to the end
|
|
bool marking{false};
|
|
bool dragging{false};
|
|
double anchor{0.0}; // station the drag started at
|
|
sweep_node *edited{nullptr};
|
|
std::string status;
|
|
};
|
|
sweep_tool m_sweep;
|
|
// paths the models along curves were laid on, so they follow the changes of the paths
|
|
struct sweep_link
|
|
{
|
|
sweep_node *sweep{nullptr};
|
|
std::size_t piece{0};
|
|
TTrack *track{nullptr};
|
|
int path{0};
|
|
bool reversed{false};
|
|
};
|
|
std::vector<sweep_link> m_sweep_links;
|
|
void sweep_curve();
|
|
void sweep_outline();
|
|
bool sweep_extend(bool const Atend, glm::dvec3 const &Cursor);
|
|
double sweep_station(glm::dvec3 const &Point, double &Lateral) const;
|
|
void sweep_scan_models();
|
|
void sweep_measure();
|
|
sweep_node::state sweep_definition() const;
|
|
void sweep_create();
|
|
void sweep_apply();
|
|
void sweep_delete(sweep_node &Sweep);
|
|
void sweep_edit(sweep_node &Sweep);
|
|
std::vector<sweep_node *> sweeps_near(TTrack const &Track) const;
|
|
bool sweep_press();
|
|
void sweep_drag();
|
|
void sweep_release();
|
|
// the same at a point of the world: Anywhere takes the press however far from the track it is
|
|
bool sweep_press_at(glm::dvec3 const &Point, bool const Anywhere);
|
|
void sweep_drag_at(glm::dvec3 const &Point);
|
|
void render_sweep_ui();
|
|
void draw_sweep_overlay() const;
|
|
void restore_sweeps(EditorSnapshot &Snapshot);
|
|
void sweeps_captured(TTrack const &Track);
|
|
void sweeps_committed(std::vector<TTrack *> const &Tracks);
|
|
void sweeps_split(TTrack &Original, TTrack &Created);
|
|
|
|
struct bend_source
|
|
{
|
|
TAnimModel *model{nullptr};
|
|
scene::instance_handle instance{0};
|
|
std::string file;
|
|
std::string skin{"none"};
|
|
std::vector<std::string> parameters;
|
|
glm::dmat4 transform{1.0};
|
|
glm::dvec3 scale{1.0};
|
|
scene::layer_handle layer{null_handle};
|
|
};
|
|
struct bend_tool
|
|
{
|
|
int axis{0};
|
|
bool turned{false};
|
|
int along_anchor{1};
|
|
int side_anchor{0};
|
|
int height_anchor{0};
|
|
glm::dvec3 point{0.0};
|
|
bool picking{false};
|
|
void const *tracks_for{nullptr};
|
|
glm::dvec3 tracks_at{0.0};
|
|
std::vector<std::pair<TTrack *, double>> tracks;
|
|
int track{0};
|
|
sweep_node *edited{nullptr};
|
|
std::string signature;
|
|
bool marker_valid{false};
|
|
glm::dvec3 marker{0.0};
|
|
std::string status;
|
|
int dragging{0}; // 1: the cross along and aside, 2: up, 3: only along, 4: the start of the model, 5: its end
|
|
sweep_node::state drag_state;
|
|
std::shared_ptr<sweep_node> drag_line; // the line as it was when the drag began
|
|
double drag_first{0.0}; // m along it, where the model began and ended then
|
|
double drag_last{0.0};
|
|
glm::dvec3 drag_anchor{0.0};
|
|
double drag_station{0.0};
|
|
std::string drag_label;
|
|
sweep_node *hover{nullptr};
|
|
bool over_marker{false};
|
|
int over_end{0}; // the handle under the cursor: 1 at the start of the model, 2 at its end
|
|
std::string label;
|
|
std::string details;
|
|
};
|
|
bend_tool m_bend;
|
|
bool bend_drag_start(int const Mods);
|
|
void bend_drag_update();
|
|
sweep_node *sweep_under(glm::dvec3 const &Point) const;
|
|
bool bend_click();
|
|
bool bend_shortcut();
|
|
bool bend_source_of_selection(bend_source &Source) const;
|
|
void bend_find_tracks(glm::dvec3 const &Point, void const *Key);
|
|
bool bend_definition(bend_source const &Source, TTrack &Track, sweep_node::state &State, std::vector<TTrack *> &Tracks);
|
|
void bend_selection();
|
|
void bend_edit(sweep_node::state const &State);
|
|
void bend_reanchor(sweep_node::state &State, int const Side, int const Height, glm::dvec3 const &Point) const;
|
|
double bend_fixed(sweep_node const &Sweep, glm::dvec3 const &Point) const;
|
|
void bend_stretch(sweep_node const &Sweep, double const Fixed, double const Length, glm::dvec3 const &Point, sweep_node::state &State) const;
|
|
// the model laid along another track: it stays where it stands, with its length
|
|
void bend_retrack(sweep_node const &Sweep, TTrack const &Track, sweep_node::state &State) const;
|
|
// the handles at the ends of the model, at the height and the side of its reference point
|
|
std::array<glm::dvec3, 2> bend_ends(sweep_node const &Sweep) const;
|
|
// a drag of the model begun: 1 the cross along and aside, 2 up, 3 only along, 4 the start, 5 the end
|
|
void bend_drag_begin(int const Kind);
|
|
// the end of the model taken to the point, the line lengthened through the tracks joined there; the length it has then
|
|
double bend_end_to(bool const Atend, glm::dvec3 const &Point, sweep_node::state &State) const;
|
|
std::string bend_selftest(std::string const &Command, std::istringstream &Words);
|
|
void sweep_relink(sweep_node const &Sweep);
|
|
void bend_pick(glm::dvec3 const &Point);
|
|
glm::dvec3 bend_marker(sweep_node const &Sweep) const;
|
|
void restore_bend(EditorSnapshot &Snapshot, bool const Undo);
|
|
void render_bend();
|
|
void draw_bend_overlay() const;
|
|
|
|
// script of editor actions given in the EU07_EDITOR_SELFTEST file, run a step at a time, for testing without a person
|
|
struct selftest
|
|
{
|
|
bool loaded{false};
|
|
std::vector<std::string> lines;
|
|
std::size_t next{0};
|
|
int wait{0};
|
|
bool quitting{false};
|
|
scripted_input input;
|
|
std::string badge; // the mouse or the keys drawn over the view, for the clips of the tutorial
|
|
glm::vec2 badge_at{0.0f}; // its bottom left corner, in the pixels of the window
|
|
};
|
|
selftest m_selftest;
|
|
using selftest_result = editor_selftest_result;
|
|
selftest_result selftest_scene(std::string const &command, std::istringstream &words);
|
|
selftest_result selftest_sleepers(std::string const &command, std::istringstream &words);
|
|
selftest_result selftest_sweep(std::string const &command, std::istringstream &words);
|
|
selftest_result selftest_track(std::string const &command, std::istringstream &words);
|
|
selftest_result selftest_switch(std::string const &command, std::istringstream &words);
|
|
selftest_result selftest_rails(std::string const &command, std::istringstream &words);
|
|
selftest_result selftest_join(std::string const &command, std::istringstream &words);
|
|
selftest_result selftest_signal(std::string const &command, std::istringstream &words);
|
|
selftest_result selftest_terrain(std::string const &command, std::istringstream &words);
|
|
selftest_result selftest_props(std::string const &command, std::istringstream &words);
|
|
selftest_result selftest_monkey(std::string const &command, std::istringstream &words);
|
|
selftest_result selftest_dispatch(std::string const &command, std::istringstream &words);
|
|
void selftest_step();
|
|
// a value typed during a gesture, taken instead of the one the cursor gives
|
|
std::string m_typed;
|
|
// what the typed value sets in the gesture under way, nullptr when the gesture takes none
|
|
char const *typed_meaning() const;
|
|
std::vector<double> typed_values() const;
|
|
bool typed_key(int const Key);
|
|
glm::dvec3 typed_lay(glm::dvec3 const &Mouse) const;
|
|
void typed_turn();
|
|
bool m_route_tab{true};
|
|
|
|
// vertical profile (grade line) along a route
|
|
struct profile_state
|
|
{
|
|
bool open{false};
|
|
TTrack *from{nullptr};
|
|
TTrack *to{nullptr};
|
|
TTrack *picked_from{nullptr};
|
|
TTrack *picked_to{nullptr};
|
|
double run_length{std::numeric_limits<double>::infinity()}; // the whole line through the track clicked
|
|
std::vector<TTrack *> followed; // the selection the route was last taken from
|
|
editor_track::route route;
|
|
std::vector<editor_track::route_sample> samples;
|
|
std::vector<TTrack *> created; // the paths the last apply split off the route
|
|
std::vector<double> terrain; // NaN where there's no terrain
|
|
std::vector<double> model; // the ground of the terrain model (NMT) as measured; NaN where it's not known
|
|
bool model_waiting{false}; // squares of the model under the route still to come
|
|
double model_polled{0.0};
|
|
// what the joined ends take their height and grade from, when it's a switch: shown on the plot
|
|
std::string start_inherits, end_inherits;
|
|
// depth of the formation under the grade line, the rail top, of the track of each sample: the formation, not the rails,
|
|
// lies on the ground
|
|
std::vector<double> beds;
|
|
profile::line line;
|
|
profile::context context;
|
|
std::vector<profile::issue> issues;
|
|
double origin{0.0}; // chainage of the start of the route
|
|
double departure{0.0}; // largest difference between the grade line and the track
|
|
profile::ground_fit fit;
|
|
// the heightmap terrain led to the grade line by a modifier: formation under the track, slopes down or up to the ground
|
|
struct earthworks
|
|
{
|
|
bool from_ballast{true};
|
|
double depth{0.7}; // m, formation below the top of the rail
|
|
double half_width{3.5}; // m, from the axis of the route to the edge of the formation
|
|
double slope{1.5}; // horizontal run of the slopes per metre of height
|
|
double reach{60.0}; // m, from the edge of the formation, where the slopes end even if they don't get to the ground
|
|
double rounding{1.5}; // m, over which the slopes bend into the formation and into the ground
|
|
bool generate{true};
|
|
// chunks of terrain made under the route by the last shaping
|
|
std::vector<std::pair<int, int>> generated;
|
|
// the modifier of the terrain made by the last shaping
|
|
std::string modifier;
|
|
} earthworks;
|
|
double view_from{0.0};
|
|
double view_to{100.0};
|
|
double view_centre{0.0};
|
|
float exaggeration{20.0f};
|
|
bool show_terrain{true};
|
|
bool show_model{true};
|
|
bool show_track{true};
|
|
bool show_plan{true};
|
|
bool whole_grade_line{true}; // applied, the tracks sharing the grade line of the route go with it
|
|
profile::line line_read; // the line before it was edited
|
|
bool fitting{false}; // the line comes from the fit to the terrain model: any error of it refuses it
|
|
std::vector<TTrack *> beside; // those of them lying by it, for the route and the state of the tracks below
|
|
std::tuple<TTrack const *, std::size_t, std::size_t, std::size_t> beside_of{nullptr, 0, 0, 0};
|
|
bool picking{false}; // a click on a track in the view puts it on the grade line of the route or takes it off
|
|
std::vector<TTrack const *> members; // of the grade line picked, wherever they are
|
|
std::tuple<int, std::size_t, std::size_t> members_of{-1, 0, 0};
|
|
int selected{-1};
|
|
int dragging{-1};
|
|
// where the point was grabbed: the mouse there, the point against the mouse; the point moves once the mouse does
|
|
ImVec2 drag_press{0.0f, 0.0f};
|
|
glm::dvec2 drag_grab{0.0};
|
|
bool drag_moved{false};
|
|
int curve_grip{-1};
|
|
bool panning{false};
|
|
bool changed{false};
|
|
double hover{-1.0};
|
|
// under the cursor in the strip
|
|
int hover_point{-1};
|
|
int hover_grip{-1};
|
|
bool hover_line{false};
|
|
int shown{-2}; // point in the side panel
|
|
bool show_remarks{false};
|
|
float strip_top{-1.0f}; // the top of the strip over the 3d view, -1 while it isn't shown
|
|
int edits{-1}; // of the tracks, when the route was last read
|
|
std::string status;
|
|
std::string error;
|
|
};
|
|
profile_state m_profile;
|
|
// grade lines designed in the editor, kept in the scenery files as "//$p" comment lines
|
|
struct stored_profile
|
|
{
|
|
scene::layer_handle layer{null_handle};
|
|
double length{0.0};
|
|
glm::dvec3 start{0.0}, end{0.0}, middle{0.0}; // of the route, world space
|
|
double origin{0.0};
|
|
profile::line line;
|
|
double departure{-1.0}; // of the track from the design when it was kept; -1 as kept by an older editor
|
|
};
|
|
std::vector<stored_profile> m_profiles;
|
|
bool m_profiles_loaded{false};
|
|
void profile_library_load();
|
|
void profile_library_mark(std::vector<scene::layer_handle> Layers);
|
|
// the last step takes the kept grade lines back to the library given, as they were before it changed them
|
|
void profiles_to_history(std::vector<stored_profile> Library);
|
|
// the kept grade lines back to the library given, the step changing them given up before it went to the history
|
|
void profiles_restore(std::vector<stored_profile> Library);
|
|
// the tracks whose grade line was fitted, by name, with the shape they had then, kept as "//$t" comment lines: a track
|
|
// changed since, by hand or taken back, isn't fitted any more
|
|
struct fitted_mark
|
|
{
|
|
scene::layer_handle layer{null_handle};
|
|
std::uint64_t shape{0};
|
|
bool hand{false};
|
|
};
|
|
std::map<std::pair<std::string, std::uint64_t>, fitted_mark> m_fitted; // by the name and the shape: scenery files have names used twice
|
|
bool m_fitted_loaded{false};
|
|
void fitted_load();
|
|
void fitted_set(std::vector<TTrack *> const &Tracks, bool const Hand = false);
|
|
bool grade_fitted(TTrack const &Track);
|
|
bool grade_hand(TTrack const &Track); // its grade line was edited with the profile tool, and it wasn't changed since
|
|
bool nmt_stays(TTrack const &Track); // this putting of the tracks onto the terrain leaves it as it is
|
|
static std::uint64_t fitted_shape(TTrack const &Track);
|
|
int profile_find(bool &Reversed) const;
|
|
bool profile_restore();
|
|
bool profile_restore_parts();
|
|
// the route a kept design was laid over, as it runs now; none when its paths moved or are gone
|
|
std::optional<editor_track::route> profile_stored_route(stored_profile const &Entry, TTrack **From = nullptr, TTrack **To = nullptr) const;
|
|
// the kept designs over the tracks moved, as by the grade lines shared, laid anew onto them where they part from them; returns how
|
|
// many were, how many couldn't be without an error and are left as they were
|
|
std::pair<std::size_t, std::size_t> profile_refit_stored(std::unordered_set<TTrack const *> const &Moved);
|
|
void profile_store();
|
|
void profile_forget();
|
|
void profile_open_stored(std::size_t const Index);
|
|
void profile_edited();
|
|
// the radii of its neighbours were for the breaks of the grade it made, they follow the limits after it
|
|
void profile_remove_point(int const Index);
|
|
void render_profile_body();
|
|
void render_profile_strip();
|
|
void render_profile_header();
|
|
void render_profile_empty();
|
|
void render_profile_toolbar();
|
|
void render_profile_points();
|
|
void render_profile_source();
|
|
bool render_profile_parameters();
|
|
void render_profile_issues();
|
|
void profile_open(TTrack *From, TTrack *To);
|
|
void profile_open_run(TTrack &Track);
|
|
void profile_take(editor_track::route Route, TTrack *From, TTrack *To);
|
|
void profile_open_selection(std::vector<TTrack *> const &Tracks);
|
|
void profile_follow_selection();
|
|
void profile_resample();
|
|
// the ground of the terrain model under the route, as it was measured before any earthworks
|
|
void profile_sample_model();
|
|
void profile_recognize();
|
|
void profile_fit_ground();
|
|
// depth of the foot of the ballast under the rail top, and its distance from the axis
|
|
static std::pair<double, double> profile_ballast(TTrack const &Track);
|
|
// false for a track with no trackbed of its own, as the switches of the older sceneries whose bed is an include
|
|
static bool profile_own_bed(TTrack const &Track);
|
|
void profile_shape_ground();
|
|
std::pair<int, int> profile_generate_ground(std::vector<std::pair<double, double>> const &Beds, double const Reach);
|
|
void profile_restore_ground();
|
|
void render_profile_earthworks();
|
|
void profile_check();
|
|
// Terrain: the heightmap terrain follows the tracks changed. Bridges: stretches of the route over a bridge or a viaduct, the
|
|
// paths over them cut off at their ends and set to the bridge environment
|
|
void profile_apply(bool const Terrain = false, std::vector<profile::departure> const &Bridges = {}, double const Fewest = 0.0);
|
|
// the terrain under the tracks changed by the last Edits steps of the history which changed tracks
|
|
void profile_follow_terrain(std::size_t const Edits);
|
|
void profile_fit_view();
|
|
// the camera to the part of the route the plot shows; the plot to the part of the route the camera shows, its zoom kept
|
|
void profile_frame_view();
|
|
void profile_to_camera();
|
|
void profile_after_undo();
|
|
void profile_follow_edits();
|
|
struct profile_view;
|
|
void render_profile_canvas(float const Height);
|
|
void profile_fit_exaggeration(profile_view const &View);
|
|
void profile_navigate(profile_view const &View, bool const Hovered);
|
|
bool profile_canvas_edit(profile_view const &View, bool const Hovered);
|
|
void draw_profile_canvas(profile_view const &View, ImDrawList &Draw) const;
|
|
void profile_canvas_tooltip() const;
|
|
void render_profile_point();
|
|
void draw_profile_overlay() const;
|
|
|
|
// infrastructure along the track: objects bound to the paths follow their changes. bindings are kept in the
|
|
// scenery files as "//$b" comment lines
|
|
struct infra_candidate
|
|
{
|
|
infra::binding binding;
|
|
double offset{0.0}; // sideways from the axis
|
|
std::string reason;
|
|
bool chosen{false};
|
|
bool bound{false};
|
|
TTrack *reader{nullptr};
|
|
std::string event; // of that path
|
|
std::string cell;
|
|
bool loose{false};
|
|
TTrack *nearer{nullptr};
|
|
glm::dvec3 nearer_foot{0.0};
|
|
bool unread{false};
|
|
};
|
|
struct infra_window
|
|
{
|
|
bool open{false};
|
|
int scope{1}; // 0: the selected path, 1: the line through it, 2: the route of the vertical profile
|
|
float reach{1500.0f};
|
|
float corridor{8.0f};
|
|
bool follow{true};
|
|
bool show{true};
|
|
std::vector<infra::rule> rules{infra::default_rules()};
|
|
std::vector<TTrack *> tracks; // of the scope
|
|
std::vector<infra_candidate> candidates;
|
|
int filter{0};
|
|
int read{0};
|
|
int overruled{0};
|
|
int unread{0};
|
|
int elsewhere{0};
|
|
int hovered{-1};
|
|
std::string status;
|
|
std::string error;
|
|
};
|
|
infra_window m_infra;
|
|
std::vector<infra::binding> m_bindings;
|
|
std::vector<std::pair<scene::layer_handle, std::string>> m_bindings_unresolved; // lines kept as they are
|
|
bool m_bindings_loaded{false};
|
|
std::vector<infra::object_state> m_infra_buffer; // states of the objects before the change in progress
|
|
std::vector<std::pair<scene::instance_handle, std::string>> m_drive_buffer;
|
|
bool m_infra_suspended{false};
|
|
// the point objects which go with a path: the signals and the warning discs it reads, the SHP resonators, and the controls of the
|
|
// block sections, the signs and the posts by the path nearest to them
|
|
struct point_object
|
|
{
|
|
scene::instance_handle include{0};
|
|
glm::dvec3 location{0.0};
|
|
TTrack *reader{nullptr};
|
|
TTrack *nearest{nullptr}; // of one no path reads
|
|
infra::category group{infra::category::other};
|
|
};
|
|
std::vector<point_object> m_point_objects;
|
|
std::size_t m_point_objects_revision{static_cast<std::size_t>(-1)};
|
|
std::size_t m_point_objects_count{0};
|
|
void infra_adopt(TTrack &Track);
|
|
int infra_bound_count() const; // by the infra tool, not the ones a change of their track took along
|
|
std::set<std::pair<scene::basic_node const *, scene::instance_handle>> m_infra_carried; // the objects their tracks moved since the tool cleared it
|
|
std::string infra_carried_note(); // a line of the status telling how many, empty for none; clears them
|
|
void infra_load();
|
|
void infra_store();
|
|
void infra_forget(scene::basic_node const *Node);
|
|
std::vector<TTrack *> infra_scope() const;
|
|
void infra_recognize();
|
|
void infra_bind_chosen();
|
|
void infra_unbind(std::vector<std::size_t> Indices);
|
|
infra::binding *infra_find(infra::binding const &Binding);
|
|
infra::object_state infra_state_of(infra::binding const &Binding) const;
|
|
void infra_restore_state(infra::object_state const &State);
|
|
void infra_buffer(infra::binding const &Binding, bool const Refresh);
|
|
// editor_track::observer
|
|
void track_captured(TTrack const &Track) override;
|
|
void tracks_committed(std::vector<TTrack *> const &Tracks) override;
|
|
void track_retired(TTrack &Track) override;
|
|
void track_split(TTrack &Original, TTrack &Created, segment_data const &First) override;
|
|
void track_renamed(TTrack const &Track, std::string const &Old) override;
|
|
void infra_move(infra::binding &Binding);
|
|
void infra_attach(EditorSnapshot &Snapshot);
|
|
void render_infra_body();
|
|
|
|
gauge_tool m_gauge{*this, *this, *this, *this};
|
|
speed_tool m_speed{*this, *this, *this, *this};
|
|
joints_tool m_joints{*this, *this, *this, *this};
|
|
vehicle_tool m_vehicle{*this, *this};
|
|
hekto_tool m_hekto{*this, *this, *this, *this, *this, *this};
|
|
fouling_tool m_fouling{*this, *this, *this, *this, *this};
|
|
parallel_tool m_parallel{*this, *this, *this, *this};
|
|
srk_tool m_srk{*this, *this, *this, *this, *this, *this};
|
|
km_tool m_km{*this, *this, *this, *this};
|
|
track_ride m_ride;
|
|
minimap_tool m_minimap{*this, *this, m_ride};
|
|
std::vector<editor_tool *> m_tools{&m_gauge, &m_speed, &m_joints, &m_vehicle, &m_hekto, &m_fouling, &m_parallel, &m_srk, &m_km, &m_ride, &m_minimap};
|
|
|
|
void infra_rebase();
|
|
void render_infra_search();
|
|
void render_infra_candidates();
|
|
void render_infra_bound();
|
|
void draw_infra_overlay() const;
|
|
|
|
bool m_route_dragging{false};
|
|
alignment::design m_route_drag_from;
|
|
float m_track_snap_radius{1.0f};
|
|
bool m_track_align_tangent{true};
|
|
bool m_track_drag_connected{true};
|
|
|
|
// roads: a menu and a window of their own, independent from the edit modes of the toolset
|
|
// what a click of the build tool would make
|
|
struct road_plan
|
|
{
|
|
std::vector<segment_data> pieces; // axes of the pieces, in the order they're laid
|
|
editor_road::loose_end snap; // loose end of a road or arm of a junction the road is led to
|
|
editor_road::branch start; // junction made, or given another arm, for a road led out of the side of a road or out of a junction
|
|
bool hasstart{false};
|
|
editor_road::branch end; // the same for a road led into the side of a road or into a junction
|
|
bool hasend{false};
|
|
std::string error; // why there's nothing to make
|
|
};
|
|
struct road_tool
|
|
{
|
|
bool window{false}; // the road window is open, the left mouse button belongs to its tools
|
|
bool lanes{true}; // lanes of the roads are drawn as trajectories
|
|
int tool{0}; // 0: select, 1: build, 2: place
|
|
road_node *selected{nullptr};
|
|
junction_node *junction{nullptr}; // selected junction
|
|
roadpoint_node *marker{nullptr}; // selected level crossing or traffic point
|
|
std::vector<glm::dvec3> points; // selected points where the pieces meet or end
|
|
road_node::state settings; // layout shown in the window: of the selected piece, or of the pieces about to be built
|
|
bool whole{true}; // layout changes go to every piece of the road the selected one belongs to
|
|
bool varied{false}; // the selected piece is shown with lanes of its own for its end
|
|
bool chain{false}; // the point to build from is set
|
|
glm::dvec3 point{0.0}; // where the next piece starts
|
|
glm::dvec2 direction{0.0, 1.0}; // the way it has to leave that point
|
|
bool hasdirection{false};
|
|
bool reversed{false}; // the pieces are laid from their ends, to carry on a road from its start
|
|
double grade{0.0}; // slope the next piece has to start with, to carry on what it's attached to
|
|
bool hasgrade{false};
|
|
// the road being built leaves the side of a road, or a junction between its roads. the point to build from is the centre
|
|
// of the junction, which gets made, or gets another arm, along with the first piece
|
|
road_node *branchroad{nullptr};
|
|
double branchat{0.0}; // value of the curve parameter of the axis of that road
|
|
junction_node *branchjunction{nullptr};
|
|
float offset{0.1f}; // height above the ground the roads are built at
|
|
bool follow{true}; // built roads are led over the ground between the clicked points
|
|
float crossingspeed{30.f}; // speed limit on the junctions being made
|
|
float heightstep{0.1f}; // how much the selected points are raised or lowered at a time
|
|
// Alt+LMB on a point dragged up or down: the heights of the selected points changed by the drag, applied when let go
|
|
bool lifting{false};
|
|
float lift_mouse{0.0f}; // where on the screen the drag began, pixels down
|
|
double lift_scale{0.0}; // metres for a pixel at the point picked
|
|
std::vector<double> lift_from; // the heights of the selected points when the drag began
|
|
bool ring{false}; // the build tool makes roundabouts
|
|
float ringradius{15.f}; // of the middle of the road going around
|
|
std::string island{"none"}; // what the middle of a roundabout is covered with
|
|
float bankgrade{1.5f}; // metres a bank led to the ground runs for each metre it drops
|
|
// level crossings and traffic points
|
|
int placekind{0}; // what the place tool puts down: 0: level crossing, 1: spawn point, 2: removal point, 3: pedestrian crossing
|
|
roadpoint_node::state placing[4]; // what the next point of each kind is going to be like
|
|
float stopmargin{5.f}; // distance from the outermost track of a new crossing to the places the vehicles stop at
|
|
roadpoint_node::state target; // the point a click of the place tool would make at the moment
|
|
bool hastarget{false};
|
|
glm::dvec3 targetdirection{0.0}; // the way the traffic goes there
|
|
std::string targetnote; // what's worth knowing about that point, or why there's none
|
|
glm::dvec3 aimed{0.0}; // where the cursor was when the target was worked out, and for what kind of point
|
|
int aimedkind{-1};
|
|
char vehicles[4096]{}; // vehicles to add to the set of a spawn point, written the way they're put in a scenery
|
|
road_plan plan; // what a click would make at the moment, worked out once a frame for display
|
|
glm::dvec3 hover{0.0}; // point of a road or a junction under the cursor a road can be led out of
|
|
bool hashover{false};
|
|
glm::dvec3 mouse{0.0};
|
|
std::string status;
|
|
};
|
|
void render_road_tool_options();
|
|
// the change of the road tool
|
|
void road_choose_tool(int const Tool);
|
|
void render_road_selection();
|
|
bool render_road_layout(road_node::state &State);
|
|
bool render_road_material(char const *Label, std::string &Value);
|
|
void render_junction_layout(junction_node &Junction);
|
|
void junction_apply(junction_node &Junction, junction_node::state const &State);
|
|
// leads the banks of the corners of a junction to the ground beside it
|
|
void junction_bank_to_ground(junction_node &Junction);
|
|
// how far from specified point, and how far down, a slope of the grade set for the banks gets to the ground.
|
|
// Outwards: the way the slope leads, seen from above
|
|
std::pair<float, float> bank_reach(glm::dvec3 const &Edge, glm::dvec3 const &Outwards);
|
|
void draw_road_overlay() const;
|
|
void update_road_tool();
|
|
void road_click();
|
|
// the point where pieces meet or end nearest to the cursor on the screen, within a few pixels; it's found under the
|
|
// terrain too, where the click on the ground doesn't get near it
|
|
bool road_joint_on_screen(glm::dvec3 &Joint) const;
|
|
// Alt+LMB: the drag of the heights of the selected points begun on a point, and finished
|
|
bool road_lift_start();
|
|
void road_lift_finish();
|
|
double road_lift_offset() const;
|
|
void road_select(road_node *Road);
|
|
void junction_select(junction_node *Junction);
|
|
void road_apply();
|
|
bool road_delete();
|
|
bool road_split();
|
|
void road_cancel();
|
|
// sets the width of the road at the selected points, or the height of each of them
|
|
void road_point_width(float const Width);
|
|
void road_point_heights(std::vector<double> const &Heights);
|
|
bool road_points_apply(std::vector<std::pair<road_node *, road_node::state>> const &Changes, std::vector<std::pair<junction_node *, junction_node::state>> const &Junctions);
|
|
// takes the selected points out of their roads
|
|
bool road_points_delete();
|
|
// puts a roundabout around specified point
|
|
void road_roundabout(glm::dvec3 const &Ground);
|
|
// leads the banks of the selected piece, or of the whole road, to the ground beside it
|
|
void road_bank_to_ground();
|
|
// level crossings and traffic points
|
|
void roadpoint_select(roadpoint_node *Point);
|
|
// works out the point a click of the place tool would make. Fresh: even if the cursor is where it was the last time
|
|
void roadpoint_aim(bool const Fresh);
|
|
void roadpoint_place();
|
|
void roadpoint_apply(roadpoint_node &Point, roadpoint_node::state const &State);
|
|
// Point: the point the controls are for, nullptr for the one about to be made
|
|
bool render_roadpoint_layout(roadpoint_node::state &State, roadpoint_node const *Point);
|
|
// Fresh: the ground which wasn't looked up yet is gathered on the spot, instead of a bit of it each frame
|
|
road_plan road_preview(bool const Fresh);
|
|
// Firstgrade, Lastgrade: slopes the road has to start and end with, nullptr for none
|
|
void road_profile(std::vector<segment_data> &Pieces, double const *Firstgrade, double const *Lastgrade, bool const Fresh);
|
|
// height of the ground under each of the points, with the roads not taken for the ground. a point with nothing under it keeps its height
|
|
// Found: set for the points which have the ground under them
|
|
std::vector<double> ground_heights(std::vector<glm::dvec3> const &Points, bool const Fresh, std::vector<char> *Found = nullptr) const;
|
|
void push_road_snapshot(editor_road::record Record);
|
|
void restore_road_snapshot(EditorSnapshot const &Snapshot, std::vector<EditorSnapshot> &Opposite, bool const Undo);
|
|
road_tool m_roadtool;
|
|
};
|