Struct default constructor - need some kind of solution for C++ interop
Ethan Watson via Digitalmars-d
digitalmars-d at puremagic.com
Fri Sep 9 07:46:31 PDT 2016
On Friday, 9 September 2016 at 12:16:00 UTC, Marco Leise wrote:
> So when you have an object that reads state from a file, you
> first construct it and then call a member function
> "loadFromFile()" that may throw? For argument's sake let's take
> a *.bmp class. That one would not have a constructor with a
> filename? Or do you have such constructors and I/O exceptions
> are just logged and swallowed?
Remedy's Northlight engine is a streaming engine (that actually
supports an open world, the legacy of Alan Wake development lives
on). Thus, you need to follow some important rules. These are
also pretty standard rules for game engines in general.
First and foremost, resources are processed offline to match the
ideal binary format for the target platform. The industry has
been using DXT textures for over a decade now, and they've been
supported on consoles. The overwhelming majority of textures are
thus baked in to such a format. Whichever format is chosen, on
disk the file will essentially represent the resource's final
layout in memory.
Second, file loading. You can't just go loading files any old
time you want in a streaming-based, or even just straight up
multithreaded, engine if you expect to keep within performance
targets and not lock up every thread you've created. They need
scheduling. Thus, resource creation needs to go through several
steps:
* Something requests a resource, goes to sleep
* File loader schedules appropriately, notifies on load complete
* Object gets resource load notification, does work to hook it up
to whatever API needs it
Anything that can assert/throw an exception is not in a
constructor in these phases. And as mentioned elsewhere, asserts
and exceptions are defined out for a retail build. If there's a
problem with the data, we expect to find it in development and
ship a product that doesn't require constant validation.
More information about the Digitalmars-d
mailing list