Resource Management in LWJGL3 | Coding a 2D Game Engine in Java #12

Поділитися
Вставка
  • Опубліковано 30 лип 2024
  • Join the Discord: / discord
    In this tutorial I go over a crucial (yet somewhat dry) element in creating a game engine, which is resource management. Even though we are coding this in Java, which is a garbage collected language, we still have to worry about how we manage our resources to avoid lag spikes, and unnecessary memory allocation. So, to combat that, we will create a class that handles all the resources (textures, shaders, sounds, spritesheets, etc.) and supply a reference to our game on demand, while only keeping one object in memory for each resource.
    Source Code: github.com/codingminecraft/Ma...
    ---------------------------------------------------------------------
    Website: ambrosiogabe.github.io/
    Github: github.com/ambrosiogabe
    Here are some books I recommend if you want to learn about game engine development more thoroughly. I do not profit off any of these sales, these are just some books that have helped me out :)
    My Recommended Game Engine Books:
    Game Engine Architecture: www.gameenginebook.com/
    Game Physics Cookbook (Read this before the next physics book): www.amazon.com/Game-Physics-C...
    Game Physics (Ian Millington): www.amazon.com/Game-Physics-E...
    Game Programming Patterns (Free): gameprogrammingpatterns.com/
    My Recommended Beginning Game Programming Books:
    JavaScript Game Design: www.apress.com/gp/book/978143...
    My Recommended Java Books:
    Data Structures/Algorithms: www.amazon.com/Data-Structure...
    LWJGL (Free, but I haven't read this thoroughly): lwjglgamedev.gitbooks.io/3d-g...
    Outro Music: www.bensound.com/royalty-free...

КОМЕНТАРІ • 24

  • @therandom446
    @therandom446 4 роки тому +9

    Yay! Almost halfway through the 2D engine. These tutorials are fantastic and I can't stress this enough, you are an amazing teacher. Thank you for putting these out there for others to learn. I'm looking forward to when i make it to the physics engine tutorial and what you have for the future.

    • @GamesWithGabe
      @GamesWithGabe  4 роки тому +4

      Thanks man! It can get tough to continue with the tutorial sometimes, so I really do appreciate these types of comments a lot! I hope that the series continues to help you out, you'll have to let me know what kind of cool things you end up making :D

    • @therandom446
      @therandom446 4 роки тому +1

      @@GamesWithGabe I absolutely will!

    • @oftenyoutuber4348
      @oftenyoutuber4348 Рік тому

      *Almost quarter way or something

  • @bencollier3758
    @bencollier3758 6 місяців тому

    What a relief! This one was mercifully short after that last beast of a 44 min tutorial. Really loving this series, thanks.

  • @HendrawanAdiWijaya
    @HendrawanAdiWijaya 4 роки тому +1

    Nice video!
    I started using AssetPool(or AssetManager in libgdx) recently in my project.

    • @GamesWithGabe
      @GamesWithGabe  4 роки тому +2

      Thanks Hendrawan! I just took a look at libgdx's asset manager and it looks like they also have a giant HashMap for their assets lol. Their asset manager is way more robust and complex then this one, but the concept remains the same :D. Also, I hadn't ever really taken a look at libgdx before this comment, and it looks pretty cool!

  • @azatakhunov6061
    @azatakhunov6061 3 роки тому +4

    java reference size is 4 bytes

  • @lucd9642
    @lucd9642 3 роки тому

    Hey Gabe, great tutorial as always! I'm learning so much from this series.
    Why exactly do you create the File object? The files being valid are already handled by the Texture / Shader classes right?

    • @GamesWithGabe
      @GamesWithGabe  3 роки тому +2

      Hey Luc, thanks for the comment :)
      The reason I create a File object in the AssetPool is because I want to store the absolute path to the different resources. Relative paths can change depending on how you're using them. So you could use 'assets/shaders/default.glsl' for the shader at one point in the code, but then at another you might pass in 'C:/myproject/assets/shaders/default.glsl' and we want to make sure that those both get the same shader (since it's the same thing). So I create the File object in the AssetPool, then get the absolute path every time to make sure we don't get any confusion with relative paths.

  • @Often_Guy
    @Often_Guy 26 днів тому +1

    12:10 When the errors is scary beast you dk how to fix

  • @luandkg
    @luandkg 4 роки тому

    😚😚😚 Great !

  • @Shadowblitz16
    @Shadowblitz16 3 роки тому

    @GamesWithGabe not sure if this is bad practice in C# you can use generics and asset inheritance to make a resource manager. you could store them into a Map

    • @GamesWithGabe
      @GamesWithGabe  3 роки тому

      I wouldn't say it's a bad practice, if it works then I would say go for it :). Resource management is still something that I can't find a really good solution for, I've tried so many different techniques and I feel like I change the way I do it every time lol. Hopefully I'll settle on a method pretty soon though

    • @Shadowblitz16
      @Shadowblitz16 Рік тому

      @@GamesWithGabe I only get 1 GL asset loaded per type even if the window is not initailized. it does however use a seperate instance for empty, default and loaded ones

  • @arcanesunku
    @arcanesunku 4 роки тому +1

    No need to call AssetPool for the shaders in your loadResources function. When you do that in the RenderBatch it does it where the renderer is called.

    • @GamesWithGabe
      @GamesWithGabe  4 роки тому +2

      Hey Tahnner, you're right it does get called in the init function as a side-effect of adding the game objects. I'm still trying to come up with a good solution that would load all resource required for a scene at initialization to ensure there aren't any lag spikes from random loading of resources in the middle of playing the scene :)

    • @arcanesunku
      @arcanesunku 4 роки тому

      @@GamesWithGabe back when I primarily did graphical programming with Java's API, I found myself making something akin to the lists we use, but I have a static init method that I call one time when the game would load up with all its resources. Though I'm not sure how that'd translate over to using LWJGL

    • @GamesWithGabe
      @GamesWithGabe  4 роки тому

      That sounds like a good solution, I'll have to try it out at some point and see about integrating it if it works well.

  • @friendsandfamily2312
    @friendsandfamily2312 2 роки тому +1

    Hey gabe, I missed the point how renderBatch runs 10 times. Can you explain it again?

    • @ToufouMaster
      @ToufouMaster Рік тому

      because you are creating a new batch when the batch is full, it was creating a new shader everytime the batch was filled

  • @chadzack9748
    @chadzack9748 3 роки тому +1

    Yo bruh, I keep getting ads with the same background music as your intro

    • @GamesWithGabe
      @GamesWithGabe  3 роки тому +2

      That's kind of weird haha. I use the music that UA-cam provides in their copyright free library so that might be why