Skip to content

Commit

Permalink
Add background loading (#1257)
Browse files Browse the repository at this point in the history
Load the next level in the background. Show progress at the top of the screen and switch to the next level once loading is complete. This stops the program from hanging during level loading which is particularly noticeable with custom levels.

Texture loading is also changed so that levels now output the textures as they are loaded (where possible - can't be done with TR4 at the moment due to the compressed data). This should cut down on the peak memory usage when loading a level as the raw data is discarded once the D3D texture has been created.

#1186
  • Loading branch information
chreden authored Jul 20, 2024
1 parent 6ee755d commit f5c6e8e
Show file tree
Hide file tree
Showing 17 changed files with 501 additions and 325 deletions.
27 changes: 11 additions & 16 deletions trlevel/ILevel.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,6 @@ namespace trlevel
// Returns: The palette colour.
virtual tr_colour4 get_palette_entry(uint32_t index8, uint32_t index16) const = 0;

// Gets the number of textiles in the level.
// Returns: The number of textiles.
virtual uint32_t num_textiles() const = 0;

// Gets the 8 bit textile with the specified index.
// Returns: The textile for this index.
virtual tr_textile8 get_textile8(uint32_t index) const = 0;

// Gets the 16 bit textile with the specified index.
// Returns: The textile for this index.
virtual tr_textile16 get_textile16(uint32_t index) const = 0;

// Get the 8 or 16 bit textile with the specified index.
// Returns: The colours for this index.
virtual std::vector<uint32_t> get_textile(uint32_t index) const = 0;

// Gets the number of rooms in the level.
// Returns: The number of rooms.
virtual uint32_t num_rooms() const = 0;
Expand Down Expand Up @@ -179,5 +163,16 @@ namespace trlevel
virtual tr_camera get_camera(uint32_t index) const = 0;

virtual Platform platform() const = 0;

struct LoadCallbacks
{
std::function<void(const std::string&)> on_progress_callback;
std::function<void(const std::vector<uint32_t>&)> on_textile_callback;

void on_progress(const std::string& message) const;
void on_textile(const std::vector<uint32_t>& data) const;
};

virtual void load(const LoadCallbacks& callbacks) = 0;
};
}
Loading

0 comments on commit f5c6e8e

Please sign in to comment.