RayLib 2D Challenge Part 11 - Collecting Coins (a.k.a., Making Objects Interact in the Game World)

Sdílet
Vložit
  • čas přidán 26. 06. 2024
  • Part 10 of the RayLib 2D Challenge ended with shiny coins beautifully animated using a texture atlas. Poor Scarfy, though. He couldn't collect the coins because the collection code hadn't been written yet. All he could do was push the coins around, and off a cliff.
    In this episode we add the missing coin collection code, complete with a satisfying "clink" sound. We also add a display overlay, so that we can count all our cash. Clink, clink, clink!
    Click the following link for a summary, and to download the code:
    keasigmadelta.com/blog/raylib...
  • Věda a technologie

Komentáře • 2

  • @mr.shredder5430
    @mr.shredder5430 Před 4 měsíci

    would threading hlep the performance just asking im still a beginner

    • @KeaSigmaDelta
      @KeaSigmaDelta  Před 4 měsíci

      Multi-threading can help performance, provided you can break the tasks down into segments that can be run in parallel. For example, running game AI code and physics code on separate cores could help. That said, multi-threaded programming can be a nightmare if you don't know what you're doing.
      Multi-threading is NOT a solution for the performance issue I mentioned in the video, though. The problem in the video is that the same files keep on being loaded from disk, which is simply wasteful of both processor time and memory. No amount of multi-threading will save you if your game's images can't fit into VRAM. When that happens, your images/textures have to be paged into and out of VRAM multiple times a frame.
      Even if it does fit into VRAM, having too many copies of the same image would mean that the GPU['s caches can't operate efficiently any more. Why? Because your many copies of the same image become too big to fit into the caches, resulting in more reads from VRAM, and slower performance. This doesn't matter with a small 2D scene like the one in the video, but when you've got 100s of megabytes of textures, and you have 100s of copies of those textures, then you will notice.
      As hinted at, the solution is a "resource manager," which will ensure that only one copy of a texture (or other resource) is loaded, and that one copy is shared between everything that uses it.