-
Notifications
You must be signed in to change notification settings - Fork 74
Ported more core examples #137
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
base: master
Are you sure you want to change the base?
Conversation
Ported |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi there. Thanks for the PR!
I put in some comments. Most of them are about general things rather than one-off specifics. For each comment, please consider other places in the other files where the same thing may happen.
I know these are ports, but I still think it is a good idea to showcase small ways in which Odin is different from C. Therefore some of the things I commented on are in the realm of "not possible in C, but easily possible in Odin, so it's a good idea to do it in these ports".
Also, sorry if some of these things are not specified by the PR checklist. I'll try to add in more specific style guide things there.
circles[i].color = colors[rl.GetRandomValue(0, 13)] | ||
} | ||
|
||
music: rl.Music = rl.LoadMusicStream("resources/mini1111.xm") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style:
Use type inference when possible. I.e. music := rl.LoadMusicStream("resources/mini1111.xm")
(please fix this and all other occurrences in the PR)
rl.InitWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "raylib [core] example - 3d camera free") | ||
|
||
// Define the camera to look into our 3d world | ||
camera: rl.Camera3D |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use initializer when possible.
I.e.
camera := rl.Camera3D {
position = {10, 10, 10}, // Camera position
// etc
}
Please fix this and other occurances
camera.fovy = 45 // Camera field-of-view Y | ||
camera.projection = .PERSPECTIVE // Camera projection type | ||
|
||
cube_position: rl.Vector3 = {0, 0, 0} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for zero init. Just do cube_position: rl.Vector3
//-------------------------------------------------------------------------------------- | ||
|
||
// Main game loop | ||
for (!rl.WindowShouldClose()) { // Detect window close button or ESC key |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra parens here and in some other places.
|
||
rl.InitWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "raylib [core] example - input mouse") | ||
|
||
ball_position: rl.Vector2 = { -100, -100 } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whenever you need to specify both type and value, then please do like this:
ball_position := rl.Vector2 { -100, -100 }
// Draw our render texture with rotation applied | ||
// NOTE: We set the origin of the texture to the center of the render texture | ||
rl.DrawTexturePro(target.texture, | ||
{0, 0, f32(target.texture.width), f32(-target.texture.height)}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can probably throw out the width and height to two f32 variables and only do the cast once that way.
|
||
rl.SetExitKey(.KEY_NULL) // Disable KEY_ESCAPE to close window, X-button still works | ||
|
||
exit_window_requested: bool = false // Flag to request window to exit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exit_window_requested := false
or exit_window_requested: bool
} | ||
|
||
// Update bunnies | ||
bunniesSize: uint = len(bunnies) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- remove
bunnies_count
- This variable doesn't use the correct naming convention, but also, it is not necessary:
- The loop below can just be
for &bunny in bunnies {}
Also, I made a new wiki page that has both some naming conventions + style conventions: https://github.com/odin-lang/examples/wiki/Naming-and-style-convention (new PRs will link to this page instead of the old naming convention page). I'll add to that document as I run into common mistakes! |
Awesome, thanks! I'm working on all the changes right now. |
I wanted to see why it looped backwards in audio_module_playing.odin, so I experimented. Since I was happy with how it worked, I pushed the changes as well. Just letting you know; don't want it to look like I was "taking over". Carry on! :) Let me know when this is ready for a second review |
SCREEN_HEIGHT :: 450 | ||
|
||
rl.InitWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "raylib [audio] example - music stream") | ||
defer rl.CloseWindow() // Close window and OpenGL context |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think moving the cleanup with defer
is useful.
My take on this is: Only use defer
when you can leave a scope in many ways, so you are sure that the cleanup happens. Don't use it when there is a single way to leave the scope. Using defer has a cost: It makes the code harder to read, as it no longer happens in the order it is stated.
Ported
core_3d_camera_mode.c
,core_input_keys.c
,core_input_mouse.c
,core_input_mouse_wheel.c
,core_window_should_close.c
, andexamples_template.c
from the official raylib examples to Odin.Checklist before submitting:
.github/workflows/check.yml
(for automatic testing)-vet -strict-style -vet-tabs -disallow-do -warnings-as-errors
core
naming convention: https://github.com/odin-lang/Odin/wiki/Naming-Convention (exception can be made for ports of examples that need to match 1:1 to the original source).