Bevy 0.12 Beginner Tutorial Series - Ep 1 - ECS & Core Concepts - Двуязычные субтитры

Hello everyone, welcome to Bevy Basics, Game Development Essentials in Bevy.
Before we start learning Bevy, I'd like to give you some background about myself and why I'm teaching this course.
I'm a former Googler and a senior software engineer.
Six months ago,
my wife and I made the decision to leave Big Tech behind us and work on something that we could call our own.
Since then, we have been working full-time towards releasing our first title, developed entirely using bevy.
While the game is still in the very early stages of development,
we feel like we've learned a lot and want to share some of that back with the community.
The goal of this series is to give you a rapid start in Vebi, while building practical game development skills.
This series is intended for all programmers, but you'll get the most out of it if you've tackled the first half of the Rust program.
There is no need for prior game development experience and none is assumed.
In terms of code references,
everything that we code together will have a link in the description so that you can go browse the GitHub repository for that at your own leisure.
With that said, I really hope you enjoy this Please subscribe to the channel for future videos to come.
In today's video, we're going to cover the following.
First, what bevy is, I'll give you an introduction to bevy explaining what makes it unique and
why it's a great choice for game development in Rust.
Next, we'll talk about the ECS architectural pattern.
how it differs from traditional object-oriented programming, and why it's beneficial for game design.
Then, we'll dive into the internals of Bevy ECS, we'll talk about storage, queries, and commands.
We'll see how Bevy's app struct ties all those things together.
and we'll wrap up with the code example.
So what exactly is Bevy?
Described by its developers, Bevy is a refreshingly simple, data-driven game mentioned built in Rust.
Rust provides unparalleled safety and performance.
While Rust has a reputation for a steep learning curve, Bebe actually makes the process smoother.
It reduces the amount of friction you encounter with the borrow checker, freeing you up the concentrate on coding.
Furthermore, despite its initial complexity, Rust empowers you to sidestep entire categories of bugs.
resulting in a smoother, more reliable development experience.
Bevy is built on a strong ECS foundation.
Bevy utilizes the Entity Component System Architecture, or ECS for short, a design pattern aimed at efficiently representing game world object.
This is one way where Bevy stands out,
while there are other game engines such as Unity and Unreal that have built ECS frameworks on top of their existing architectures,
Bevy has been designed with ECS as its foundational architecture from the very beginning.
Bevy is very quickly rising in popularity.
In just three years, Bevy has amassed 25,000 GitHub stars showcasing rapid adoption and interest.
Additionally, it has over 800,000 downloads on Create's IO and a vibrant Discord community of 14,000 users.
Bevy is continuously evolving, adding new features, and proving that it is on a path to becoming a major player in the gaming industry.
Now, let's get into the basics of ECS or Entity Component System architectures.
and see how they compare to the more common object-oriented programming.
In object-oriented programming, you might have a class for spaceship with various attributes and methods all bundled together.
An update-position method might define behavior from moving the spaceship by accessing the class's fields.
In contrast, ECS separates the concerns of data and behavior into different parts.
There's three things, entities, components, and systems.
Entities are just unique IDs or references that point to In essence,
they connect all the components together to make up a single object in your game world.
Components are just pure data structures like the position or velocity that we see in this example.
Systems then are just functions that operate on the entities with specific components.
So in ECS, our spaceship would be an entity, and its position and velocity would be the components that that entity consists of.
A system would then handle the movement based on the position and velocity component.
In this case, we can see a query that reads velocity and position, and then updates the position based on the velocity.
The key thing to note here is that in ECS, data is stored in components, and behavior is stored in systems.
There is not a tight coupling between the update position function and the spaceship.
There is no class for the spaceship.
Instead, the spaceship is just an entity that is spawned into the game world with two components.
In object-oriented programming, the update-position method is defined inside the spaceship class.
In other words, the behavior is tightly coupled with the data defined in the class.
To reiterate, ECS stands out for its ability to bring unparalleled flexibility and potential for parallel execution to game development.
By decoupling data from behavior, ECS allows you to write systems that operate in making your game logic reusable and easier to manage.
This separation of concerns not only simplifies your codebase, making it more maintainable, but also gives you the ability to fully leverage multi-core processors.
Systems and ECS can run in parallel as long as they don't have conflicting data dependencies, resulting in a significant boost in performance.
performance, especially for games with lots of entities.
Now that you understand the basics of ECS architectures in general, let's talk specifically about Babbi ECS and its storage layer.
You can think of Babbi ECS like an in-memory database.
Rose, our entity.
qualities, columns are the components that the entity has.
In Bevy ECS, world is the name of the data structure that stores and exposes operations on all the entities and components in your application.
Interacting directly with the world data structure is very uncommon in Bevy.
And Bevy provides commands and queries, which are abstractions that allow you to interact with the world.
So let's learn more about how you can spawn entities and query components.
Commands provide a safe, efficient, and deferred way to modify your game's state, facilitating like spawning.
design, despawning, and adding components to entities, while queries offer immediate access to existing components, enabling data retrieval and mutation within the ECS architecture.
Spawning entities,
for example,
is as simple as calling commands.spawn and then passing in a tuple of all the components that you want that entity to consist of.
Quering components is also simple.
You define the pipe signature in your system.
of the data that you want to query.
In this example, we have a query with two components, velocity and position.
Based on the type signature, Bevy uses a form of dependency injection to automatically supply your systems with the necessary data.
In other words, this means you don't have to manually pass all of your data around.
You don't make direct calls to these functions,
Bevy's scheduler takes care of running your systems and providing them with the appropriate components and resources they need to operate.
Before we move on, let's better understand why Bevy includes two different abstractions for interacting with entities and components.
Critically, since queries only interact with the components and not the underlying entity hierarchy,
they can be executed in parallel in less two systems both query the same component type and at least one axis is mutable.
In other words,
if you have multiple read-only queries,
for example, multiple systems that want to read position but not modify it, they can all execute in parallel.
Commands the other hand require exclusive access to the world and cannot be applied in parallel,
when you call methods on the command struct in Bevy.
For example, if you call commands.spawn in one of your systems, Those commands are actually stored in a queue.
Commands automatically executed by Bevy when it's safe to mutate the world.
That is, once other systems have run and Bevy's schedule can execute a that has exclusive world access.
In summary, queries and commands are abstractions that allow you to interact with the bevy ECS storage layer, or world, safely and efficiently.
Queries allow your systems to run in parallel while reading or modifying components.
Commands also allow your systems to run in parallel.
well, by deferring the execution of those commands to a system with exclusive world access.
As you can see, Bevy is built with performance in mind.
When developing games in Bevy, you will use both of these abstractions very frequently.
You might be wondering how we actually execute our application logic in Bebe.
Up until now, we haven't talked about what goes in the main function.
The answer to this is the app.
In Bebe, the app struct ties together all the elements of the ECS architecture and executes your code.
It holds your game's data.
the schedule, and the runner function.
The schedule is essentially a list of systems and the order in which they should be run.
The runner function manages the application's event loop,
each frame, it executes the schedule, calling both Bevie's internal systems, and the systems that you've added to the app, through the add systems function.
in the order configured.
The function is provided by Bevy.
All you have to do is call run on your app, after the default plugins.
We will learn more about plugins later.
For now, just think of a plugin as a grouping of application logic and its associated settings.
The default plugins add the default runner function and windowing support in Bevy.
I know that was a lot of really dense information, now we're going to switch gears and do some hands-on coding.
I encourage you to code along with us to enhance your learning.
We're going to create a new Rust project using Cardo new.
We're going to navigate to the project's directory.
Do Cardo add bevy to include bevy as the dependency.
The only other thing that I strongly recommend you do is go into your Cardo tomal file.
add a of to enable performance optimizations.
This will make certain operations a lot less slow, such as loading large asset files.
Let's start coding.
We're going to start by importing a bevy prelude.
This brings everything we might need to build a simple application in We're going to create a barebones app and bring in the default plugins.
Default plugins are provided by the bevy prelude and will allow a window to be rendered.
At this point, if we were to run our application, an empty window would appear and the application would run until it is closed.
For this first video, we won't render anything to the screen.
Instead, our goal is to simply spawn an entity,
create components, and use queries and commands to interact with the ECS storage layer that we've discussed in this video.
Next, we're going to define two components, position and variable.
drawing inspiration from our earlier Spaceship example.
Using derived component, Rust generates the necessary code to make a type of Bebby component, allowing integration with Bebby's ECS.
This drive attribute makes the component creation process simple and defines the trait component automatically,
allowing you to focus on defining the data and not worrying about integrating it with Bevy's ECS storage.
In Bevy, components are highly versatile and can be any data type, including enums, structs, and zero-sized marker types.
Next, we'll define the SPON spaceship function.
Add Mute commands to your system's function parameters to obtain a command queue.
As we discussed,
the command queue enables modifications to the world, ensuring safe and orderly changes within the ECS environment by deferring the execution of those commands.
to another system that Bevy runs later.
Swan creates an entity, adding it to Bevy's ECS storage layer.
The spaceship entity is defined by its components, which in this case are position and velocity.
We use a tuple to group these components together and attach them to the entity upon space.
By doing this, the spaceship becomes part of the world, and its components can be accessed and modified by different systems in our game.
Now that we've defined the spawn spaceship function, we need to go ahead and add the system to the startup schedule.
In other words, we need to register the function that we've created with Bevy so that it can know to execute it.
By using the startup schedule, we're making it run at the very beginning of our app when everything starts up.
On startup, Bevy automatically runs the system, injecting the required parameters.
While this automatic parameter passing might feel like magic at first, it actually enables a cleaner and more organized architecture for our Bebe applications.
Now let's create a second function.
Update position which will take a query.
The query is going to fetch two components, a read-only reference to velocity.
and immutable reference to position.
The first type parameter in the query type defines the data that you want to access.
We can either take references or immutable references to the component types that we've defined.
For accessing multiple components, you simply group them together in a tuple and provide that tuple as a type to the query.
In the same way that Bevy will inject the commands queue to our startup system, Bevy is going to inject the required data.
to our update position function.
In the function body, we're going to simply iterate over both components for every entity in the query.
This accesses the ECS storage and fetches every entity with the corresponding components that we've defined in our type signature.
Then, for each of these components,
we simply add the velocity x to the position x and the velocity y to the position y in order to update the component that defines the position for the entity.
We need to make sure position is muted.
both in the declaration in the type signature, and when we iterate over it in the query because we are updating the position component.
Next, we'd like to be able to add a simple way to inspect the data that we've updated in our previous system.
In order to do this, we'll define another separate system that will query the entities and their components.
In this case, we won't worry about the velocity component.
We can still query the same entities using only the position component, specified in the query type.
We're going to iterate over all entities Zinn will output the entity ID and position values by using Vevy's built-in
info macro in order to log them to the console.
This will allow us to see what's happening as the game loop runs and the schedule is executed each frame.
Finally, we'll add the update position and print position systems to the update schedule.
The update schedule runs once every frame, and is usually where you add all the core game logic.
Babbi is going to call these systems for every iteration of the game.
we now have a working application that we can run.
Again, you don't need to manually manage the game loop yourself.
Just by defining an app, adding systems to it and calling run, Bevy does that for you.
As an application developer, this is great.
Before wrapping up, let's take a quick look at the output of running the code example.
As you can see, Bevy is automatically executing our systems.
As the game loop runs, we see the info macro calls being outputted to the console.
The running code displays the from the print position system and each frame logs the entity ID in this continuously updated position.
And that concludes our very first session.
I hope you stay tuned because I have a lot more topics I want to cover in this series.
I'm excited to share what I've learned using Bevy full-time for the past six months.
Topics will range from organizing your code efficiently using bundles and plugins to understanding and managing global state with resources.
We'll also learn about system ordering, run conditions, and events.
We'll also step up our code examples.
We'll explore Bevy's 3D capabilities and build some really neat examples that incorporate
the top as we've learned in this video and future videos to come.
This is the first YouTube series that I've created and it's been a learning experience for me.
I'm not the best public.
I'm growing in this process, and I hope you'll come along with the journey and join us to make a great series together.
Your feedback is critical to me,
so please drop a comment,
let me know the future topics that you'd like me to cover, or anything I can change to make this more accessible for you.
I know we all have different backgrounds and different levels of experience.
So if there's anything that I can do to make this series more accessible to you, I'd love to hear that feedback.
With that said, I hope you all have a great day and I'll see you in the next video.
Язык перевода
Выбрать

Разблокируйте больше функций

Установите расширение Trancy, чтобы разблокировать больше функций, включая AI-субтитры, AI-определение слов, AI-анализ грамматики, AI-речь и т. д.

feature cover

Совместимость с основными видеоплатформами

Trancy не только обеспечивает поддержку двуязычных субтитров для платформ, таких как YouTube, Netflix, Udemy, Disney+, TED, edX, Kehan, Coursera, но также предлагает AI-перевод слов/предложений, полноэкранный погружной перевод и другие функции для обычных веб-страниц. Это настоящий всесторонний помощник в изучении языков.

Все платформы браузеров

Trancy поддерживает все платформы браузеров, включая расширение для браузера iOS Safari.

Несколько режимов просмотра

Поддерживает театральный, чтение, смешанный и другие режимы просмотра для всестороннего двуязычного опыта.

Несколько режимов практики

Поддерживает режимы диктовки предложений, устного оценивания, множественного выбора, диктовки и другие режимы практики.

AI-сводка видео

Используйте OpenAI для сводки видео и быстрого понимания ключевого контента.

AI-субтитры

Создавайте точные и быстрые AI-субтитры YouTube всего за 3-5 минут.

AI-определение слов

Нажмите на слова в субтитрах, чтобы найти определения с помощью AI.

AI-анализ грамматики

Анализируйте грамматику предложений, чтобы быстро понять их значение и освоить сложные грамматические моменты.

Дополнительные веб-функции

Помимо двуязычных видео субтитров, Trancy также предоставляет перевод слов и полноэкранный перевод для веб-страниц.

Готовы начать

Попробуйте Trancy сегодня и оцените его уникальные возможности самостоятельно