6163 Commits

Author SHA1 Message Date
Tamás Bálint Misius
b26d057783
Store tool identifier to index mapping in tools.index
This mimics sim.walls.* rather than elem.*_PT_*. The latter is fine because element identifiers follow the *_PT_* pattern, but tool identifiers don't, so they'd be a pain to tell apart from the rest of the API.
2024-10-04 12:09:14 +02:00
Tamás Bálint Misius
c03c2f3fd0
Fix Lua elements getting deselected when their properties change
This was because element tools associated with Lua elements were reallocated every time their properties changed. They are now properly updated instead.

This is still a mess and I don't like it at all.
2024-10-04 09:53:51 +02:00
Tamás Bálint Misius
82ec6b2775
Fix yet another extremely rare pmap corruption
Don't just set the .type of struct Particle to 0, kids. Code tracked back to the times from before git; already present in b0ea52690ba5, the initial commit.

Reproduce with

	sim.clearSim()
	elem.property(elem.DEFAULT_PT_DMND, "Update", function(i, x, y)
		local ni = sim.photons(x, y)
		if ni then
			if not sim.partProperty(ni, "vx") then
				print(x, y)
				assert(false)
			end
		end
	end)
	local i = sim.partCreate(-1, 100, 100, elem.DEFAULT_PT_NEUT)
	sim.partProperty(i, "vx", 0)
	sim.partProperty(i, "vy", 2)
	sim.partCreate(-1, 100, 100, elem.DEFAULT_PT_DMND)
	sim.partCreate(-1, 100, 102, elem.DEFAULT_PT_PRTI)
	sim.paused(true)
	sim.framerender(1)

Though if done this way, it's actually a photons corruption.
2024-10-03 10:58:28 +02:00
Tamás Bálint Misius
126e636eb3
Appease the clang gods (fix CI) 2024-10-02 20:19:01 +02:00
Tamás Bálint Misius
2a7a6a40fd
Fix gravity lensing applying uniformly to all of RGB
Broken in 7e9d9686dda4, where I accidentally applied the offset calculated for the red channel to all channels, oops.
2024-10-02 20:05:21 +02:00
Tamás Bálint Misius
7c578b7f13
Port brushes to PlaneAdapter 2024-09-29 16:41:29 +02:00
jacob1
3b3162063f
Fix issues with render ui checkboxes: (fixes #970)
Render mode checkboxes each control multiple bit flags, but they would fully unset all bits they control, even if they shared flags with other render modes (which they always do). This would cause more things to turn off than intended when deselecting options, and all other checkboxes would appear unchecked. Now it will recalculate render mode based on what's checked instead.

Air display mode checkboxes are supposed to act as radio buttons, but it was letting all air modes be selected at once. They are mutually exclusive because only one display background can be drawn at once. Now, they act as exclusive radio buttons again.
2024-09-22 00:27:08 -04:00
Tamás Bálint Misius
c842086309
Pause renderer thread when needed in GameModel 2024-09-15 18:25:37 +02:00
Tamás Bálint Misius
12322bb382
Snapshot 370 snapshot-370 2024-09-14 19:45:25 +02:00
Tamás Bálint Misius
00ec4e0754
Implement Lua tools 2024-09-14 13:49:53 +02:00
Tamás Bálint Misius
ff4500620e
Make GameModel tool list persistent
That is, it's not thrown away and rebuilt every time the underlying set of tools changes (the "derivation" approach). Rather, changes to the underlying set are applied to GameModel's list (the "persistent" approach).

Normally, I'd prefer the derivation approach if its overhead is small enough, which in this case it would be. However, this change, among a few others, is done in preparation for exposing tool functionality to Lua. The Lua side will use persistent numeric identifiers to refer to tools, which means at least Lua tools would need to follow the persistent approach, at which point it makes more sense for all tools to do so, than a hybrid approach.
2024-09-14 13:26:22 +02:00
Tamás Bálint Misius
c1a859c106
Move custom GOL management to GameModel
Also use RGB<uint8_t> for storing custom colors.
2024-09-14 13:09:44 +02:00
Tamás Bálint Misius
352c6227f6
Blow up Tool.cpp into smaller files
It's all still a good old mess though.
2024-09-14 13:09:44 +02:00
Tamás Bálint Misius
a26544ba95
Move tool logic out of Simulation
Also uncurse WindTool in the process; it is now an ordinary SimTool. This required extending SimTool with a Drag method that is called every tick while the user prepares for drawing a line and is shown the preview.

Since the Simulation doesn't have to understand SimTools anymore, they don't have to be a part of SimulationData and so NoToolClasses.cpp can finally be removed from the renderer executable.
2024-09-14 13:09:44 +02:00
Tamás Bálint Misius
2ae5b9209c
Don't force update powder.pref if the session is still invalid 2024-09-14 13:09:44 +02:00
Tamás Bálint Misius
6da42933c4
Fix find mode always reporting 0 particles found
Somehow foundElements (now renamed to foundParticles) made it into RendererSettings in 820f44a71690, even though it's actually a result of the rendering process. It is now extracted the same way as the resulting frame.
2024-09-07 15:13:24 +02:00
Tamás Bálint Misius
65aa34201b
Expose sim.canMove constants 2024-09-01 17:44:58 +02:00
Tamás Bálint Misius
867b8e4327
Bump android target sdk version to 33
See https://support.google.com/googleplay/android-developer/answer/11926878?hl=en
2024-08-31 09:03:28 +02:00
Tamás Bálint Misius
f58d4fbd63
Implement Platform::DefaultDdir for android
The default directory is acquired via getExternalFilesDir. Typical value: /storage/emulated/0/Android/data/uk.co.powdertoy.tpt/files, which seems to be user-accessible both on old and new Android. Probably. Hopefully. We'll see.
2024-08-30 21:25:54 +02:00
jacob1
5180df9180
Fix @tags description 2024-08-25 00:27:18 -04:00
jacob1
c7b3dc5582
Press F1 in save search to open help text + document new advanced search
I tried to document everything the advanced search does, but it was mostly a guessing game discovering all its features. It appears to be insanely powerful, supporting AND, OR, negation, parenthesis,quote-encapsulated phrases, and limiting search to only certain fields. These can be chained together as well. I tried giving examples that could possibly be useful.

Terms like before: and after: are not part of advanced search, and thus are global search options even if they're inside parenthesis
2024-08-25 00:23:11 -04:00
jacob1
cb9285bbe4
Fix crash when opening render settings 2024-08-21 20:21:58 -04:00
Tamás Bálint Misius
800c48f8bd
Snapshot 369 snapshot-369 2024-08-22 00:06:17 +02:00
Tamás Bálint Misius
79459bcff3
Copy the result of rendering only if needed
That is, only if the Renderer needs to immediately blast off to render another frame. If we run it on the main thread, we can just use its video buffer directly.
2024-08-21 23:48:13 +02:00
Tamás Bálint Misius
eb29d5a9dd
Unify decoration state
Also make paste previews follow the current renderer settings.
2024-08-21 23:48:13 +02:00
Tamás Bálint Misius
bf5f9fdcb0
Expose threaded rendering as a setting 2024-08-21 23:48:13 +02:00
Tamás Bálint Misius
a9b84e5f26
Hide away some more Renderer functions 2024-08-21 23:48:13 +02:00
Tamás Bálint Misius
820f44a716
Do rendering on another thread when possible
"Possible" here means "when there are no particles with Lua graphics functions that haven't reported that they don't want to be called again and there are no beforesimdraw/aftersimdraw event handlers". I put my trust in Simulation::elementCount here; I sure hope it's always correct. If there is any of these, the renderer thread is paused and rendering happens on the main thread. To be clear, these are the situations in which Lua code is called with LuaScriptInterface::eventTraits having the eventTraitSimGraphics bit set.

If the detection of this situation is somehow flawed, there will still be no crashes because when running on the renderer thread, Renderer is told to not call Lua functions, and GameController::BeforeSimDraw/AfterSimDraw is not called by GameView::RendererThread. The worst that can happen is that some particles are not rendered properly.

Renderer settings (color and display modes, deco state, finding-element state, etc.) are managed by GameModel in the form of a RendererSettings and are passed to Renderer before each frame. The RenderableSimulation that Renderer works off of is also configured before each frame, either to point to a copy dedicated to the renderer thread, or directly to GameModel's Simulation, if the renderer thread is paused. Similarly, the result of the rendering is managed by GameView in the form of a RendererFrame, to enable e.g. sampling with deco tools without having to pause the renderer thread.

Each time GameView::OnDraw is called, it checks whether rendering is allowed to happen on a different thread (see above for conditions).

If it is, but the renderer thread is absent, GameView starts it and dispatches it (provides with settings and simulation data) right away. At this point, the renderer thread is definitely rendering a frame. GameView waits for this to finish and exchanges data with the renderer once it's done: it takes the result of the rendering and also dispatches the renderer thread again. This introduces a one-frame delay in rendering, which we can live with.

If rendering is not allowed to happen on a different thread, GameView waits for the renderer thread to finish what it's currently doing and pauses it, then proceeds to render the frame by itself.

Affecting this condition (whether rendering is allowed to happen on a different) by installing or removing event handlers, or clearing graphics cache (which, note, requires acquiring a unique lock on it), while the renderer thread is working, is not an issue because the renderer thread doesn't bother with event handlers, and because it acquires a shared lock on the graphics cache for rendering.

The GameModel's Renderer is thus still primarily managed by GameView, potentially in two different threads, in a strictly non-overlapping manner. The exception to this is when RenderView butts in and starts doing renders of its own; in such cases, the renderer thread must be paused explicitly, as RenderView does by calling GameView::PauseRendererThread.
2024-08-21 23:48:13 +02:00
Tamás Bálint Misius
77edec62d1
Make Renderer presets static 2024-08-21 19:30:15 +02:00
Tamás Bálint Misius
f52e047037
Move sampling further away from Renderer 2024-08-21 19:30:15 +02:00
Tamás Bálint Misius
7f60a44d1c
Move brushes further away from Renderer 2024-08-21 17:18:00 +02:00
Tamás Bálint Misius
d5c2d87b2e
Move zoom further away from Renderer 2024-08-21 17:17:42 +02:00
Tamás Bálint Misius
4ed83912af
Get rid of render and display mode arrays
These were arrays because that made them easy to compose, but that's a UI task, it makes no sense to propagate them internally. That said, RenderView is still confusing because it still has checkboxes that control multiple bits of render mode and display mode at once; I'm not dealing with that for now.

The game now prefers the item-type preferences Renderer.RenderMode and Renderer.DisplayMode over the array-type preferences Renderer.RenderModes and Renderer.DisplayModes. It'll preserve the old ones for compatibility if found and derive the new ones from them. The corresponding Lua functions are now deprecated and will just return single-item arrays from now; the similarly named replacements operate with integers.
2024-08-21 17:16:06 +02:00
Tamás Bálint Misius
6e01699a7f
Separate Simulation-specific Renderer code
Also decouple Simulation lifetime from Renderer lifetime. This also let me get rid of the hack that was RendererFont.cpp.
2024-08-21 17:15:58 +02:00
Tamás Bálint Misius
c1a072f2e5
Separate Simulation members required for rendering
More precisely, move them to RenderableSimulation, which Simulation now inherits from. This type is copyable and so is easy to send off to be rendered, potentially on a different thread.
2024-08-21 17:15:49 +02:00
Tamás Bálint Misius
d24a70d6d1
Make pmap size sanity check more precise
Simulations as big as 2048 by 2048 had been possible, but this change enables sizes such as 1900 by 2100, which would have failed the originally very power-of-2-oriented check. Very useful, no doubt.

Also make the tags button span the entire window, fixing the annoying gap or overlap with other buttons when changing the sim size.
2024-08-21 17:15:30 +02:00
Tamás Bálint Misius
57f6ea5953
Fix a few warnings 2024-08-18 13:23:07 +02:00
Tamás Bálint Misius
1854bc25f0
Replace &range[0] with range.data() where appropriate
I had been under the impression that .data() on containers returns a const pointer and so hadn't been using it too much. I was wrong; I think that may be limited to std::basic_string. EDIT: I've checked, even std::basic_string has a non-const .data() since C++17, nice.
2024-08-18 13:23:06 +02:00
Tamás Bálint Misius
ba0a9fa2a5
Snapshot 368 snapshot-368 2024-08-13 20:43:39 +02:00
Tamás Bálint Misius
8e03c97b60
Fix broken gravity walls
They stopped working because 7e9d9686dda4 accidentally had BeforeSim reset the gravity mask also, not just the gravity mass from the previous frame.
2024-08-13 20:39:16 +02:00
Tamás Bálint Misius
2d03fb4b56
Fix resource depfile generation
I got the escaping wrong so on windows, where the path to the script has characters that need to be escaped, the script wouldn't be found, leaving all dependents stale, triggering rebuilds of all resources.
2024-08-07 10:56:56 +02:00
Tamás Bálint Misius
281dbfa283
Make to-array.py list itself as a dependency of its outputs
This causes these dependencies to be rebuilt if the script chanages, which is heaps better than having to remember to clean the build directory every time.
2024-08-07 10:20:43 +02:00
Tamás Bálint Misius
295aad1800
Mark dlls as link-time dependencies of powder.exe
So they get copied into the build site even if you invoke only the powder build target, rather than all build targets by not specifying one. Case in point:

	meson compile

vs

	meson compile powder

wherein the latter will build powder.exe but will not copy the dlls into the build site, which are required by powder.exe.
2024-08-06 07:26:12 +02:00
Tamás Bálint Misius
c97cc1ec51
Slightly smarter Defer 2024-07-25 10:45:27 +02:00
Tamás Bálint Misius
daea125837
Disable the requestHandles.size() assert in Libcurl.cpp
It's getting triggered because the lifetime of some objects that own RequestHandles are not exactly deterministic, to put it lightly. I'm not dealing with those.
2024-07-21 14:00:44 +02:00
dxgldotorg
6179a7383a
Add HiDPI to manifest file, fixes #956 2024-07-06 21:12:52 +02:00
Tamás Bálint Misius
c7bb950cfc
Snapshot 367 snapshot-367 2024-07-03 21:25:58 +02:00
Tamás Bálint Misius
7e9d9686dd
Change gravity timing and add support for saving it
Timing is now such that the input to the gravity process (the point masses and the mask derived from gravity walls) is passed in BeforeSim and the output of the gravity process (the 2D force field) is taken also in BeforeSim, at the same time. This means that input generated by particles in frame n is passed to the gravity process at the beginning of frame n+1, the corresponding output is available by the beginning of frame n+2, and so it is visible to particles in frame n+2. Thus, gravity is now properly and predictably one frame late, though, sadly, it's displayed two frames late.

This is in contrast with the case of not being late at all, which would be the case if input generated in frame n produced visible output by frame n+1, and also in contrast with what we've had until now, which was that gravity was *at least* one frame late, but it could be more out of sync than that if the gravity process for some reason took more time to produce output.

Further, both input and output now make it into snapshots and saves, which fixes one half of what causes the phenomenon wherein beams of PHOT under the effect of gravity wiggle for a few frames before stabilizing after a save is loaded. The other half is that velocities are saved at very a low precision, so overall, the effect of this change on this phenomenon is negligible.

It is not crucial that a client understands this new piece of info, as clients have been fine not getting gravity data from saves for years. Thus, its presence does not restrict the save to client versions newer than the one that adds this feature.

An interesting question this brings up is whether settings, crucially, the enabled state of Newtonian gravity, should be considered simulation state and be also included in saves.

Gravity data is now also included in the output of sim.hash, so Newtonian gravity no longer has to be disabled in order to ensure local determinism.

The diff is large because I gave up on being non-invasive and renamed important structures that lots of elements use. gravp, which was functionally just hypot(gravx, gravy), was removed, because it was only ever used to display a single value in the HUD. I've also taken a few detours and made changes that really should have been in separate commits, see below, but oh well.

This commit also includes a complete rework of the gravity wall area of effect discovery algorithm. The old implementation was extremely broken even beyond the usual C99-isms.

Also fix Simulation.NewtonianGravity being read as an integer from powder.pref, even though it's a boolean and is in fact saved as a boolean. It's pure luck that it's worked fine until now.

Also introduce PlaneBase for use with PlaneAdapter. PlaneBase is a very budget version of std::span from C++20, so budget in fact that it doesn't even store span size; this is fine because PlaneAdapter knows the span size anyway. std::basic_string_view worked for char types but this new code deals with floats.

Also include blockAir data in saves unconditionally. It used to be included only if ensureDeterminism was enabled, like rngState and frameCount, but those last two are conditionally included only because some assumptions are broken if they are included, such as that of expecting a saved simulation to take different paths of evolution after each reload. blockAir has no such effect.

Also remove sim.resetGravityField aka tpt.reset_gravity_field because it was agreed that it's really weird that the output of the gravity process can be changed at all from Lua, not to mention that it can only be reset to zero. No scripts to my knowledge ever used these functions.
2024-07-03 20:51:05 +02:00
Tamás Bálint Misius
0345dcf508
Spam hdiutil until it works 2024-07-03 20:51:05 +02:00
yangbowen
24628db58b Add support for clang-cl. Also refactors compiler detection logic. 2024-07-03 20:49:46 +02:00