Attachments
Attachments
Attachments
Attachments
Code: Select all
density = enemyCount / heat
Code: Select all
tension = targetDensity / density
Attachments
Code: Select all
density = enemyCount / heat
Code: Select all
tension = targetDensity / density
Attachments
I should do this too! I rely on my phone for that when there's no need, besides writing on my comically small 3.5" phone screen is uncomfortable (that's the point of having such a tiny phone, so that I don't use it more than it's necessary). What do you use for writing? I'm a bit wary of keeping pens in my pocket as they easily break.Kampffrosch wrote: Wed Mar 11, 2026 6:48 am I try to always carry a cheap a6 notebook in my pocket, so I can just jot down some thoughts or tasks for later and free up my mind in the moment.
I should do this too! I rely on my phone for that when there's no need, besides writing on my comically small 3.5" phone screen is uncomfortable (that's the point of having such a tiny phone, so that I don't use it more than it's necessary). What do you use for writing? I'm a bit wary of keeping pens in my pocket as they easily break.Kampffrosch wrote: Wed Mar 11, 2026 6:48 am I try to always carry a cheap a6 notebook in my pocket, so I can just jot down some thoughts or tasks for later and free up my mind in the moment.
Anything I would do with a calculator I rather do in my head or on paper.
Anything I would do with a calculator I rather do in my head or on paper.
Code: Select all
uiInteraction.BeginRecording("some-unique-key");
foreach (var child in children) {
child.Draw(...);
}
var childInScrollbar = uiInteraction.EndRecording("some-unique-key");
Attachments
Code: Select all
uiInteraction.BeginRecording("some-unique-key");
foreach (var child in children) {
child.Draw(...);
}
var childInScrollbar = uiInteraction.EndRecording("some-unique-key");
Attachments
Attachments
Attachments
Attachments
Attachments
Just where it hurtsno formal proof for you
Just where it hurtsno formal proof for you
eheheheSugui wrote:Just where it hurts
eheheheSugui wrote:Just where it hurts
Let's take a moment to appreciate a time where StackOverflow was filled with good, insightful questions (such as mineI have an array of N elements (representing the N letters of a given alphabet), and each cell of the array holds an integer value, that integer value meaning the number of occurrences in a given text of that letter. Now I want to randomly choose a letter from all of the letters in the alphabet, based on his number of appearances with the given constraints:
Now, taking that into account, I've come up with a simple algorithm that might do the job, but I was just wondering if there was a better thing to do. This seems to be quite fundamental, and I think there might be more clever things to do in order to accomplish this more efficiently. This is the algorithm i thought:
- If the letter has a positive (nonzero) value, then it can be always chosen by the algorithm (with a bigger or smaller probability, of course).
- If a letter A has a higher value than a letter B, then it has to be more likely to be chosen by the algorithm.
So, is there a better thing to do than this? Am I missing something?
- Add up all the frequencies in the array. Store it in SUM
- Choosing up a random value from 0 to SUM. Store it in RAN
- While RAN > 0, Starting from the first, visit each cell in the array (in order), and subtract the value of that cell from RAN
- The last visited cell is the chosen one
I'm aware most modern computers can compute this so fast I won't even notice if my algorithm is inefficient, so this is more of a theoretical question rather than a practical one.
I prefer an explained algorithm rather than just code for an answer, but If you're more comfortable providing your answer in code, I have no problem with that.
Now, I must admit, even today, this answer flies slightly over my head. I wouldn't blame you if putting that binary search in there makes you feel uneasy, especially when you still have to iterate through all the elements so the complexity of the whole thing would be linear anyway. I have implemented this version at least once in the past and it seems to work, and things like binary searches tickled my past self's brain in the right way, so I marked it as accepted.The idea:Example:
- Iterate through all the elements and set the value of each element as the cumulative frequency thus far.
- Generate a random number between 1 and the sum of all frequencies
- Do a binary search on the values for this number (finding the first value greater than or equal to the number).
Generate a random number in the range 1-10 (1+4+3+2 = 10, the same as the last value in the cumulative list), do a binary search, which will return values as follows:Code: Select all
Element A B C D Frequency 1 4 3 2 Cumulative 1 5 8 10
Code: Select all
Number Element returned 1 A 2 B 3 B 4 B 5 B 6 C 7 C 8 C 9 D 10 D
Attachments
Let's take a moment to appreciate a time where StackOverflow was filled with good, insightful questions (such as mineI have an array of N elements (representing the N letters of a given alphabet), and each cell of the array holds an integer value, that integer value meaning the number of occurrences in a given text of that letter. Now I want to randomly choose a letter from all of the letters in the alphabet, based on his number of appearances with the given constraints:
Now, taking that into account, I've come up with a simple algorithm that might do the job, but I was just wondering if there was a better thing to do. This seems to be quite fundamental, and I think there might be more clever things to do in order to accomplish this more efficiently. This is the algorithm i thought:
- If the letter has a positive (nonzero) value, then it can be always chosen by the algorithm (with a bigger or smaller probability, of course).
- If a letter A has a higher value than a letter B, then it has to be more likely to be chosen by the algorithm.
So, is there a better thing to do than this? Am I missing something?
- Add up all the frequencies in the array. Store it in SUM
- Choosing up a random value from 0 to SUM. Store it in RAN
- While RAN > 0, Starting from the first, visit each cell in the array (in order), and subtract the value of that cell from RAN
- The last visited cell is the chosen one
I'm aware most modern computers can compute this so fast I won't even notice if my algorithm is inefficient, so this is more of a theoretical question rather than a practical one.
I prefer an explained algorithm rather than just code for an answer, but If you're more comfortable providing your answer in code, I have no problem with that.
Now, I must admit, even today, this answer flies slightly over my head. I wouldn't blame you if putting that binary search in there makes you feel uneasy, especially when you still have to iterate through all the elements so the complexity of the whole thing would be linear anyway. I have implemented this version at least once in the past and it seems to work, and things like binary searches tickled my past self's brain in the right way, so I marked it as accepted.The idea:Example:
- Iterate through all the elements and set the value of each element as the cumulative frequency thus far.
- Generate a random number between 1 and the sum of all frequencies
- Do a binary search on the values for this number (finding the first value greater than or equal to the number).
Generate a random number in the range 1-10 (1+4+3+2 = 10, the same as the last value in the cumulative list), do a binary search, which will return values as follows:Code: Select all
Element A B C D Frequency 1 4 3 2 Cumulative 1 5 8 10
Code: Select all
Number Element returned 1 A 2 B 3 B 4 B 5 B 6 C 7 C 8 C 9 D 10 D
Attachments
Code: Select all
unsafePerformIO $ print "help!!"Code: Select all
unsafePerformIO $ print "help!!"I really like the idea behind "write-only" globals and you've made me realize a lot of the globals I use are like that. Print is definitely a write-only global, at least in spirit (I don't care if you can access the internal buffer, nobody will).palas wrote: Sat Mar 14, 2026 12:40 am Types 1 and 2 are in the safe category, so spamming them won't hurt too much. When it comes to 3, they directly affect how well can one reason about the codebase locally.
This is still mostly unsolved for me. It's not about whether or not to use them (can't really gamedev much without at least some global scene/level manager), but how to design in a way to keep as much locality as possible. For example, if I'm storing references to game objects, they can still be deleted from anywhere else. What happens if they do get deleted? Idk
Code: Select all
if (SceneGraph.GetFirstEntityInGroup("Player") is not {} player) return;
Code: Select all
if (SceneGraph.GetFirstEntityInGroup("Player") is not {} player) return;
TweenManager.Spawn(..., tick: (t) => {
player.color = somethingSomething(t);
});
I really like the idea behind "write-only" globals and you've made me realize a lot of the globals I use are like that. Print is definitely a write-only global, at least in spirit (I don't care if you can access the internal buffer, nobody will).palas wrote: Sat Mar 14, 2026 12:40 am Types 1 and 2 are in the safe category, so spamming them won't hurt too much. When it comes to 3, they directly affect how well can one reason about the codebase locally.
This is still mostly unsolved for me. It's not about whether or not to use them (can't really gamedev much without at least some global scene/level manager), but how to design in a way to keep as much locality as possible. For example, if I'm storing references to game objects, they can still be deleted from anywhere else. What happens if they do get deleted? Idk
Code: Select all
if (SceneGraph.GetFirstEntityInGroup("Player") is not {} player) return;
Code: Select all
if (SceneGraph.GetFirstEntityInGroup("Player") is not {} player) return;
TweenManager.Spawn(..., tick: (t) => {
player.color = somethingSomething(t);
});
Code: Select all
fn Entity::handle(self) -> Handle<Self>;
fn Handle<T>::get(self) -> T?;
Code: Select all
fn Entity::handle(self) -> Handle<Self>;
fn Handle<T>::get(self) -> T?;
Code: Select all
(def ^:dynamic *user-session* nil)
(def auth-middleware [request, next-fn]
(if-let [session (validate-user-session (-> request :cookies :user-session-cookie))]
(binding [*user-session* session]
(next-fn))
#_else
(throw "somethingsomething unauthenticated")))
Code: Select all
(def ^:dynamic *user-session* nil)
(def auth-middleware [request, next-fn]
(if-let [session (validate-user-session (-> request :cookies :user-session-cookie))]
(binding [*user-session* session]
(next-fn))
#_else
(throw "somethingsomething unauthenticated")))
Oh yup! I have things like this. Not for entities (maybe I should?), but for components I have a ComponentRef thing that's basically this. Maybe I should add a similar thing for entities, though nothing would enforce using an entity handle over just passing an entity around, so I'm not fully convinced therePalas wrote: As for the API to handle potentially missing entities... The first thing that comes to mind is Handle<T> with the following api:Code: Select all
fn Entity::handle(self) -> Handle<Self>; fn Handle<T>::get(self) -> T?;
Oh yup! I have things like this. Not for entities (maybe I should?), but for components I have a ComponentRef thing that's basically this. Maybe I should add a similar thing for entities, though nothing would enforce using an entity handle over just passing an entity around, so I'm not fully convinced therePalas wrote: As for the API to handle potentially missing entities... The first thing that comes to mind is Handle<T> with the following api:Code: Select all
fn Entity::handle(self) -> Handle<Self>; fn Handle<T>::get(self) -> T?;
Code: Select all
if value.inner is Inner inner
&& inner.inner is Inner inner
&& inner.inner is Inner inner {...}
Code: Select all
if value?.inner?.inner is Inner inner {...}
Code: Select all
if value.inner is Inner inner
&& inner.inner is Inner inner
&& inner.inner is Inner inner {...}
Code: Select all
if value?.inner?.inner is Inner inner {...}
Code: Select all
if value?.inner?.inner is Inner inner {...}
Code: Select all
if value is Str(s) && s.trim().to_lower() == "potato" { ... }
Code: Select all
if value?.inner?.inner is Inner inner {...}
Code: Select all
if value is Str(s) && s.trim().to_lower() == "potato" { ... }
Code: Select all
if (Input.IsActionJustPressed(InputAction.Attack) {
...
}
Code: Select all
if (Input.IsActionJustPressed(InputAction.Attack, out var actionBinding) {
if (actionBinding.IsMouse()) {
// mouse aim logic
}
else {
// aim where the character is facing based on movement
}
}
Code: Select all
if (Input.IsActionJustPressed(InputAction.Attack) {
...
}
Code: Select all
if (Input.IsActionJustPressed(InputAction.Attack, out var actionBinding) {
if (actionBinding.IsMouse()) {
// mouse aim logic
}
else {
// aim where the character is facing based on movement
}
}
Very interesting, I've never considered this aspect. So it's not possible to differentiate between someone moving their cursor with a mouse vs steam controller?As an owner of a steam controller, I know how annoying it is when games use mouse movement as an indicator that the player is using keyboard and mouse, so I'm not gonna do that.
A bit confused by this. Even if the player uses the mouse to attack, they are still using the keyboard for movement. Could attack action be bound to both mouse and keyboard at the same time? That way, both styles are combined in one.Using keyboard input as a predictor that the player is playing with their mouse is thus not possible.
Ha! Before you showed your API, I've pictured something like:Problem is, if my code has any sort of special logic that depends on the input device, as I described above, I need to undo that, and... check each input device manually?
Code: Select all
if Input.Pressed(InputAction.Attack) is action {
match action {
ActionType::Mouse => {},
ActionType::Controller => {}
}
}
Most likely another classic instance of "we do whatever is most simple for a beginner, any slightly more complicated use case is the user's problem".I'm very mad no other engine has it.
Very interesting, I've never considered this aspect. So it's not possible to differentiate between someone moving their cursor with a mouse vs steam controller?As an owner of a steam controller, I know how annoying it is when games use mouse movement as an indicator that the player is using keyboard and mouse, so I'm not gonna do that.
A bit confused by this. Even if the player uses the mouse to attack, they are still using the keyboard for movement. Could attack action be bound to both mouse and keyboard at the same time? That way, both styles are combined in one.Using keyboard input as a predictor that the player is playing with their mouse is thus not possible.
Ha! Before you showed your API, I've pictured something like:Problem is, if my code has any sort of special logic that depends on the input device, as I described above, I need to undo that, and... check each input device manually?
Code: Select all
if Input.Pressed(InputAction.Attack) is action {
match action {
ActionType::Mouse => {},
ActionType::Controller => {}
}
}
Most likely another classic instance of "we do whatever is most simple for a beginner, any slightly more complicated use case is the user's problem".I'm very mad no other engine has it.
Well the thing is, I have keyboard and keyboard&mouse as two separate input schemes, and I want to implement a feature (attack in the direction the mouse is pointing at) that should only work in one of the two cases. If you are using keyboard-only and the mouse happens to be left of your character, your attacks will always go to the left which would be badpalas wrote: Mon Mar 16, 2026 3:04 am A bit confused by this. Even if the player uses the mouse to attack, they are still using the keyboard for movement. Could attack action be bound to both mouse and keyboard at the same time? That way, both styles are combined in one.
Hehe, good one! Pretty much the same thing I came up with. Actually, I'm using that DUnion source generator you shared a while back for this, and the `.IsMouse()` in my code was auto-generated from the union, but I could've used at `.Match(...)` as well!
When I had this issue in Godot, I had to fall back to the non "input action" API, so checking the keyboard, mouse and gamepad devices directly without going through the abstraction layer. I'm not sure if it's any better now but all their "is_action_*" methods return a boolean, and judging by GDScript's limitations, it's unlikely they return anything else anytime soon ^^'']]>palas wrote: Mon Mar 16, 2026 3:04 am Most likely another classic instance of "we do whatever is most simple for a beginner, any slightly more complicated use case is the user's problem".
But, surely every half competent engine has a way to tell whether a mouse or a controller is used, and process each one separately? This is such a fundamental feature after all.
Well the thing is, I have keyboard and keyboard&mouse as two separate input schemes, and I want to implement a feature (attack in the direction the mouse is pointing at) that should only work in one of the two cases. If you are using keyboard-only and the mouse happens to be left of your character, your attacks will always go to the left which would be badpalas wrote: Mon Mar 16, 2026 3:04 am A bit confused by this. Even if the player uses the mouse to attack, they are still using the keyboard for movement. Could attack action be bound to both mouse and keyboard at the same time? That way, both styles are combined in one.
Hehe, good one! Pretty much the same thing I came up with. Actually, I'm using that DUnion source generator you shared a while back for this, and the `.IsMouse()` in my code was auto-generated from the union, but I could've used at `.Match(...)` as well!
When I had this issue in Godot, I had to fall back to the non "input action" API, so checking the keyboard, mouse and gamepad devices directly without going through the abstraction layer. I'm not sure if it's any better now but all their "is_action_*" methods return a boolean, and judging by GDScript's limitations, it's unlikely they return anything else anytime soon ^^'']]>palas wrote: Mon Mar 16, 2026 3:04 am Most likely another classic instance of "we do whatever is most simple for a beginner, any slightly more complicated use case is the user's problem".
But, surely every half competent engine has a way to tell whether a mouse or a controller is used, and process each one separately? This is such a fundamental feature after all.
Code: Select all
//this function never exits
fn panic() -> ! {
...
}
Code: Select all
let opt = Some(10);
let value: i32 = match opt {
Some(v) => v,
None => panic!("it crashed"); // ! is converted to i32, as in this branch we never return anyway
};
Code: Select all
let x = foo(return 5);
Code: Select all
let x = match value {
Some(v) => v,
None => return None,
};
Code: Select all
=> { return None; }
Code: Select all
fn zombiejesus() {
loop {
while (return) {
if (return) {
match (return) {
1 => {
if (return) {
return
} else {
return
}
}
_ => { return }
};
} else if (return) {
return;
}
}
if (return) { break; }
}
}
Code: Select all
let x = {
{ return; };
5
};
Code: Select all
//this function never exits
fn panic() -> ! {
...
}
Code: Select all
let opt = Some(10);
let value: i32 = match opt {
Some(v) => v,
None => panic!("it crashed"); // ! is converted to i32, as in this branch we never return anyway
};
Code: Select all
let x = foo(return 5);
Code: Select all
let x = match value {
Some(v) => v,
None => return None,
};
Code: Select all
=> { return None; }
Code: Select all
fn zombiejesus() {
loop {
while (return) {
if (return) {
match (return) {
1 => {
if (return) {
return
} else {
return
}
}
_ => { return }
};
} else if (return) {
return;
}
}
if (return) { break; }
}
}
Code: Select all
let x = {
{ return; };
5
};
Attachments
Attachments
Attachments
Attachments
Attachments
Attachments