I've been reading about how to design code for a game. One thing I haven't been able to figure out is - how do you manage writing an outside-game level editor (not an 'in-game level editor') without 'copying' code from the game? For example, you might have to copy all code about the different types of entities you can have. You'll have to add the game rendering code.

My guess is this can be done by making a DLL out of the 'engine' part of the game. Then, share it between the actual game and the level editor.

For even larger projects you might want to separate the Engine Core over multiple projects like Core, Physics, Graphics, Audio, Input and Networking. All these projects can't reference each other, but they all reference Core where you can store some common base types.

If they would reference each other the separation would be useless.

Anyway this should help you reuse parts of your engine in other projects. For example for the editor you would need to reference the Graphics project which references Core itself.

This separation also means that you can now use Windows Only technologies, like WPF, in your editor while your game can still target Windows and XBLIG.

Hey that's true, but that sample is from 2008, before WPF really got off the ground. I've switched from WinForms to WPF a year ago and I wouldn't for the world switch back :). If you want to stay compatible with that sample you could always use the WinFormsControlHost in a WPF app :).
–
Roy T.Mar 31 '12 at 19:50

Separate out rendering logic as best as you could from actual game logic when designing your game engine. One way of doing this is to use Component pattern when building your game engine. For example, XNA uses this pattern at the framework level for flexibility. Use the same code-base for rendering with your level editor; write wrappers if you have to.

Similarly, another somewhat popular pattern is MVC (Model-View-Controller) which could also help. Code your engine using MVC normally. You can then use the same code for View and Model, but inject a custom Controller for editing the Model for your level editor instead of the game engine's Controller that updates according to game input. Implement serialization for game Models to load/save them from editor or game.

Keeping components in separate assemblies will of course encourage separation...