It's free to join Gamasutra!|Have a question? Want to know who runs this site? Here you go.|Targeting the game development market with your product or service? Get info on advertising here.||For altering your contact information or changing email subscription preferences.
Registered members can log in here.Back to the home page.

Search articles, jobs, buyers guide, and more.

by David Lanier
Gamasutra
June 14, 2000

Printer Friendly Version

Letters to the Editor:
Write a letter
View all letters


Features

 

Contents

Modifiers

Utilities

The Microsoft Foundation Classes

Possibility of Using the Microsoft Foundation Classes in Utility Plug-Ins

Plug-ins are usually developed using the Microsoft Windows Win32 API. But with utility plug-ins you can use the Microsoft Foundation Class as well. The Microsoft Foundation Class Library is an "application framework" for programming in Microsoft Windows. The MFC framework is a powerful approach that lets you build upon the work of expert programmers for Windows. As far as I know, utility plug-ins are the only plug-in type where MFC can be used. To download a skeleton utility that uses MFC, have a look at the Discreet web site: http://www.ktx.com/mfc.

Advantages of Using MFC

MFC shortens development time, provides tremendous support without reducing programming freedom and flexibility, and gives its user easy access to "hard to program" user-interface elements and technologies. MFC makes it easy to program features like property sheets ("tab dialogs"), print preview, and floating, customizable toolbars.

If you use the Microsoft Visual C++ compiler, MFI is fully integrated with the development environment interface. For example: you have the MFC ClassWizard which helps you to map messages and controls from your dialog boxes; since version 6.0 of Microsoft Visual C++, it automatically shows the member functions of the class while typing. This is not possible when using the Win32 API because a lot of functions use a window handle (HWND) and global functions to deal with your dialog boxes controls. This means, for example, that there is no class regrouping all functions of the list boxes or combo boxes - while in MFC, you have the CListBox and CComboBox classes.

For example, when you want to empty a list box using the Win32 API, you have to use the following function:

SendMessage(
  (HWND) hWnd,     // handle to destination window
  LB_RESETCONTENT, // message to send
  (WPARAM) wParam; // not used; must be zero
  (LPARAM) lParam; // not used; must be zero
);

You have to know the HWND of your list box. And messages processing is a burden to use.

In MFC, you just have to do :

ClistBox MyListBox;       // list box that has been mapped
MyListBox.ResetContent(); 
//This is part of the CListbox class, no message processing in //your code (although it is done implicitly)

Moreover, a strong advantage of MFC over the Win32 API is that you can download a lot of complete MFC projects with source code. So you rarely start from scratch when you have to do, for instance, a treeview with the drag and drop functionalities enabled. Have a look at the following web site to download some examples of MFC projects: http://codeguru.com . This web site has everything you need to use MFC; I managed to save a couple of weeks using existing code.

Drawbacks of Using MFC

You should probably know before choosing to use the MFC inside 3D Studio Max that you won't be getting any support from Discreet. MFC is not officially supported, so you have to use it at your own risk. This will be a concern with pure MFC problems and problems with integration of MFC inside 3D Studio Max. Here are some of the strange problems you may encounter when combining the two:

Most of the problems met when using MFC are 3D Studio Max functions from the kernel that don't work. For example, when using release 3 or later, if you want to have customizable keyboard shortcuts for your plug-in (which are very useful), you need to call the functions ActivateShortCutTable and DeactivateShortcutTable as follows:

//This is a class to create the keyboard shortcuts
class PluginShortcutManagerCB : public ShortcutCallback
{
  virtual BOOL KeyboardShortcut (int id);
}
const ShortcutTableId kMappingShortcuts = 0x34f274f4;

//Create an instance of this class
PluginShortcutManagerCB* mappingShortcutCB = new PluginShortcutManagerCB;
Interface* ip = GetCoreInterface();

//Activate the shortcuts
ip->ActivateShortcutTable(static_cast < ShortcutCallback* >       (mappingShortcutCB), kMappingShortcuts);

//DeActivate the shortcuts
ip->DeactivateShortcutTable(static_cast < ShortcutCallback* >       (mappingShortcutCB), kMappingShortcuts);

And DeactivateShortcutTable crashes each time you call it when using MFC, while it works fine when you use just the Win32 API.

To solve this problem, I have created another DLL, using only the Win32 API, which links with my MFC DLL and then I register, activate and deactivate the keyboard shortcuts by calling functions in this Win32 DLL. It's a patch, but it works fine!

So there are issues with using MFC, but to date I have always been able to solve the problems that I've run into when using MFC.

Conclusions

Let's wrap this up. A modifier is a plug-in made to modify objects in some way and that benefits from the geometry pipeline, while a utility is a plug-in that is useful for implementing modal procedures but is not designed (in theory) to modify objects.

In my opinion, modifiers should be used when you can't develop a utility, because utility plug-ins are simpler to develop. A utility should be developed to:

  1. Get information from the scene without modifying objects, or

  2. Modify objects only if the objects can have their modifier stacks collapsed, or

  3. Drive modifiers and build a "super utility plug-in".

So knowing the constraints and the specifications of the tool that you have to develop, you should now be able to choose wisely between the two types of plug-in, as well as the Microsoft Foundation Classes. And remember: programming in 3D Studio Max, your code might not always look nice, not when you have to make things work in any way you can, but you usually can make things work.

Acknowledgments and References

Thanks to Jurie Horneman for his help in writing this article.

Further information about this topic can be found at:
- The Discreet web site : http://www.discreet.com
- The 3D Studio Max SDK Forums : http://support.discreet.com/~200
- The 3D Studio Max Open source forums: http://support.discreet.com/~maxopensource
- Gamasutra article about Developing 3D Studio Max plug-ins
- Using Max with MFC : http://www.ktx.com/mfc


David Lanier is a programmer working for Kalisto Entertainment France (http://www.kalisto.com ). In the past four years, Kalisto has developed games such as Dark Earth, Ultimate Race Pro, The Fifth element, 4 Wheel Thunder and Nightmare Creatures II. David has been working in the R&D department as a tool developer for the last two years. The R&D team focuses on technologies, tools and processes allowing the game teams to focus on gameplay. David is specialized in developing tools that deal with real-time texture-mapped 3D graphics. He can be reached at dlanier@free.fr, you can visit his web page on http://dlanier.free.fr.

_________________________________________________

[Back to] Modifiers


join | contact us | advertise | write | my profile
news | features | companies | jobs | resumes | education | product guide | projects | store



Copyright © 2003 CMP Media LLC

privacy policy
| terms of service