Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raycast function returns what it hit #2631

Merged
merged 5 commits into from
Sep 18, 2023

Conversation

MatusGuy
Copy link
Member

@MatusGuy MatusGuy commented Sep 8, 2023

No description provided.

@pazkero
Copy link
Contributor

pazkero commented Sep 8, 2023

LGTM, for what little good it does.

@MatusGuy
Copy link
Member Author

MatusGuy commented Sep 8, 2023

little good??? I need this.

@mrkubax10 mrkubax10 added type:feature category:code status:needs-review Work needs to be reviewed by other people labels Sep 8, 2023
@HybridDog
Copy link
Contributor

If I understand this change correctly, from a user perspective it does nothing. Why do you need this change?

@MatusGuy
Copy link
Member Author

MatusGuy commented Sep 8, 2023

I'm trying to change zeekling's behaviour in order to make it more predictable: #2624
and for that im doing raycasting

@pazkero
Copy link
Contributor

pazkero commented Sep 10, 2023

little good??? I need this.

No, I mean my opinion does you little good, you need mrkubax or Vankata or Tobbi or any other C++ coder (up to and including Semphriss, I assume) to this go ahead, the fact I approve is not going to help you.

@MatusGuy
Copy link
Member Author

ah sorry for misunderstanding ur right

src/collision/collision_system.cpp Outdated Show resolved Hide resolved
src/collision/collision_system.cpp Outdated Show resolved Hide resolved
src/collision/collision_system.hpp Outdated Show resolved Hide resolved
@mrkubax10
Copy link
Member

Apparently designated initializers (i.e. .tile = tile) are available since C++20.

@MatusGuy
Copy link
Member Author

huh???? ive been doing c++17??? How do i initialize then? Every other way has resulted in compiler error. Any examples?

@mrkubax10
Copy link
Member

mrkubax10 commented Sep 15, 2023

You are probably using GCC which is much less pedantic about standard than for example Clang or MSVC (though it tends to add it's own weird features lol).

@mrkubax10
Copy link
Member

Any examples?

First define the union as not anonymous:

union RaycastHit
{
  const CollisionObject* object;
  const Tile* tile;
};

struct RaycastResult
...

Then use it in struct RaycastResult:

RaycastHit hit;

Initialize it the normal way (for example):

RaycastHit hit;
hit.tile = tile;

And use in return value:

return {true, hit, tilebox};

@MatusGuy
Copy link
Member Author

I see. Do they get initialized as nullptr by default?

@MatusGuy
Copy link
Member Author

You are probably using GCC which is much less pedantic about standard than for example Clang or MSVC (though it tends to add it's own weird features lol).

I believe i was using clang at the time

@mrkubax10
Copy link
Member

I see. Do they get initialized as nullptr by default?

Since all union members use the same memory (they are overlapping), only one of them is valid which means that you can't initialize other members.

@Rusty-Box Rusty-Box merged commit a81441b into SuperTux:master Sep 18, 2023
29 of 33 checks passed
@mrkubax10 mrkubax10 removed the status:needs-review Work needs to be reviewed by other people label Oct 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants