Difference between world and worldimp?

Everything about development and the OpenMW source code.
Post Reply
mattwla
Posts: 59
Joined: 17 Jul 2017, 14:45

Difference between world and worldimp?

Post by mattwla » 05 Aug 2017, 00:28

Hi,

What is the difference between world.hpp and worldimp.hpp? It seems that everything in world.hpp is defined in worldimp.cpp, and all in worldimp.hpp is also defined in worldimp.cpp

How are these classes related? Why are they separate?

Thank you,

Chris
Posts: 1558
Joined: 04 Sep 2011, 08:33

Re: Difference between world and worldimp?

Post by Chris » 05 Aug 2017, 08:47

mattwla wrote:
05 Aug 2017, 00:28
What is the difference between world.hpp and worldimp.hpp? It seems that everything in world.hpp is defined in worldimp.cpp, and all in worldimp.hpp is also defined in worldimp.cpp
world.hpp is the interface for the MWWorld subsystem that other subsystem's can use. worldimp.hpp declares the implementation of the MWWorld subsystem, which can contain internal details that other subsystems don't need to know about (keeping interface and implementation separate is good for ensuring private data stays private, and doesn't require recompiling everything that uses the interface because a new non-interface thing was modified). And worldimp.cpp defines the functions and such that actually run. Almost all the subsystems follow this pattern.

mattwla
Posts: 59
Joined: 17 Jul 2017, 14:45

Re: Difference between world and worldimp?

Post by mattwla » 05 Aug 2017, 13:21

Thanks Chris,

So, to make sure I understand. world.hpp declares the public functions of the MWWorld subsystem, worldimp.hpp declares the private, and all MWWorld functions public or private are defined in worldimp.cpp?

Chris
Posts: 1558
Joined: 04 Sep 2011, 08:33

Re: Difference between world and worldimp?

Post by Chris » 05 Aug 2017, 23:00

mattwla wrote:
05 Aug 2017, 13:21
Thanks Chris,

So, to make sure I understand. world.hpp declares the public functions of the MWWorld subsystem, worldimp.hpp declares the private, and all MWWorld functions public or private are defined in worldimp.cpp?
Basically, yeah. Though the "public functions" in world.hpp are what's known as "pure virtual" interface. They're virtual methods that belong to a class that has no explicit implementation. Instead, worldimp.hpp derives from the interface, overriding the virtual methods with ones that get implemented. That's one of two common ways to separate interface from implementation in C++.

Post Reply