Advertisement

loading multiple .ms3d files at once

Started by August 22, 2002 06:40 PM
13 comments, last by NJamesW 22 years, 6 months ago
Thanks Nukem, I''ll try it out once I get back from visiting my girlfriend and let you know.
OK, I haven''t been able to get it to work (probably has something to do with my sorry programming skills )

Let me rephrase what I want to happen and then I''ll display my code.

What I want to happen is when I open the dialog box it loads a milkshape 3d file. OK, the problem is when I load a new .ms3d file, it loads it, but it replaces the old one. I realize why this happens, because the variable file_name in the code below, but, I still have no idea how to fix this. Any help?

Here''s the code:


  LRESULT CALLBACK WndProc(	HWND	hWnd,	UINT	uMsg,	WPARAM	wParam,	LPARAM	lParam)		{OPENFILENAME open_params = {0}; char filter[BUFF_MAX] = {0}; char file_name[BUFF_MAX] = {0}; 							        			if(LOWORD(wParam) == ID_MILK_FILE_OPEN)			{								strcat(filter,"MS3D Files");				int index = strlen(filter) + 1; 				filter[index++] = ''*'';				filter[index++] = ''.'';				filter[index++] = ''m'';				filter[index++] = ''s'';				filter[index++] = ''3'';				filter[index++] = ''d'';							FillOpenParams(open_params,hWnd,filter,file_name);				pModel = new MilkshapeModel();				modelswitch=TRUE;				if(GetOpenFileName(&open_params))				{				if ( pModel->loadModelData( file_name ) == false )				{				MessageBox( NULL, "Couldn''t load the model data\\model.ms3d", "Error", MB_OK | MB_ICONERROR );				return 0;									// If model Didn''t Load Quit				}				}			}	}	return DefWindowProc(hWnd,uMsg,wParam,lParam);}void FillOpenParams(OPENFILENAME &open_params, HWND hwnd, char *filter, char *file_name){	open_params.lStructSize = sizeof(OPENFILENAME); 	open_params.hwndOwner = hwnd;	open_params.lpstrFilter = filter;	open_params.lpstrFile = file_name; 	open_params.nMaxFile = BUFF_MAX; 	open_params.lpstrInitialDir = NULL; 	open_params.lpstrFileTitle = NULL; 	open_params.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_NOCHANGEDIR						| OFN_HIDEREADONLY;}  

Advertisement
Here is what you should do, make a linked list. It is best for what you are trying todo. You wont have to add too much code. A C++ book should tell you how to make one if not search www.planetsourcecode.com for a linked list tutorial. It will give you the ablitly to be able to load unlimited models(only limited by your memory) and the ablity to be able to delete and add more models as time goes on. It seems like its just what you need.
--------------------------Nukemmsn: nukem996@hotmail.comaim: nukem996open source open mind
OK, sorry to keep bothering you, but, can give you give me an example and/or simple definition of a linked list and try to explain it to me? I looked around for some examples, but, all the ones I found just confused me, my C++ book''s example also confused me (it''s also a few chapters ahead of where I am at). Thanks, in advance and if you don''t feel like doing it or have the time that''s cool.
What a linked list is something to hold an unlimited amount of data. Usally(infact every time ive seen a link list used) it is held in a struct. In the struct can be data even funtions of any sort. The most import one is the next that makes a pointer to were the next place of data is in memory.

The struct looks something like this.


  struct LINKEDLIST{   MS3D model;   LINKEDLIST* next; //pointer to the next place in the list};  


Into order to add, delete, and get data you need to write some funtions. These funtions will let you use the linked list.

The first thing we need to do is create and add data to the linked list so here is what we do.


  LINKEDLIST model = 0;void Add(LINKEDLIST** Head, char* FileName){	LIKEDLIST* temp = *Head; //create a temp list        //goto the end of the list	while (temp != NULL)	{		temp = temp->next;	}        //if the list is empty create a new list	if(*Head == NULL)	{		*Head = new LINKEDLIST; //create the new list		 Head->model.load(FileName); //load the data		(*Head)->next = NULL; //point to the next part of the list	}	else //if were just adding to the list	{		LINKEDLIST* temp = new LINKEDLIST; //create a temp list		Head->model.load(FileName); //load the data		temp->next = *Head; //point to the next part of the list		*Head = temp; //load the data into the list	}}  


That would load a model in our linked list. The next thing we would want to do is get the data from the linked list and display the model.


  void PrintList(item* Head){        //if the list is empty exit	if(Head == NULL)  {		return;	}	LINKEDLIST* temp = Head; //make a temp list        //keep displaying till were at the end of the list	while (temp != NULL)	{		temp->model.Display(); //display the model		temp = temp->next; //goto the next part of the list	}}  


The next thing we would want to do is delete an item in the list.


  void KillItem(M3UINFO** Head, int ToLookFor){    if(*Head == NULL)	return; //if list is empty exit    //if the data is in the first part of the list    if ((*Head)->Model.Data == ToLookFor)    {	LISTEDLIST* temp = *Head; //create a temp list	*Head = (*Head)->next; //show the place in the list after the place we are deleting	delete temp; //delete the data	return; //exit    }		LISTEDLIST* temp1 = *Head; //create a temp list		LISTEDLIST* temp2 = (*Head)->next; //create a temp place to the next place in the list                //keep going to the end of the list		while(temp2 != NULL)		{                        //if we have found the data we are looking for			if(temp2->model.Data == ToLookFor)			{				temp1->next = temp2->next; //show the place in the list after the place we are deleteing				delete temp2; //delete the data				return; //exit			}			temp2 = temp2->next; //goto the next place in the list			temp1 = temp1->next; //goto the next place in the list		}	}  


Now you might want to clear the list. All you do is this.


  void KillLst(LINKEDLIST** Head){	LINKEDLIST* temp = NULL; //create a temp list        //go threw the list till were at the end	while(*Head != NULL)	{	    temp = *Head; //the temp list = the real list	    *Head = (*Head)->next; //goto the next part of the list	    delete temp; //delete the data	}}  


Now you should be able to make a linked list for your program. Incase you want an example here is a program I made years ago when I first learned linked list.


  #include <iostream.h>#include <string.h>struct item  {	char name[80];	int amount;	item* next;};void AddItem(item** Head);void PrintList(item* Head);void KillItem(item** Head);void KillList(item** Head);void mnu();int main(void){	item* Head = NULL;	int a = 0;	bool go = true;	mnu();	do{		cout << endl;		cout << "Function: ";		cin >> a;		switch(a){			case 1:			cout << endl;			AddItem(&Head);			break;			case 2:			cout << endl;			PrintList(Head);			break;			case 3:			cout << endl;			KillItem(&Head);			break;			case 4:			cout << endl;			KillList(&Head);			break;			case 5:			cout << endl;			mnu();			break;			case 6:			cout << endl;			cout << "Exiting. . .\n";			go = false;			break;		}	}while(go == true);	return 0;}void AddItem(item** Head){	char name[80];	double a;	char q;	cout << "Item: ";	cin.getline(name, sizeof(name));	cin.getline(name, sizeof(name));	cout << "Amout of ''" << name << "'' to add to list: ";	cin >> a;	item* temp = *Head;	while (temp != NULL)	{		if(strcmp(temp->name, name) == 0)		{			temp->amount += a;			cout << "Item added " << a << " times.\n";			return;		}		temp = temp->next;	}	if(*Head == NULL)	{		*Head = new item;		strcpy((*Head)->name, name);		(*Head)->amount = a;		(*Head)->next = NULL;	}	else	{		item* temp = new item;		strcpy(temp->name, name);		temp->amount = a;		temp->next = *Head;		*Head = temp;	}	cout << "Item added " << a << " times.\n";}void PrintList(item* Head){	cout << "List:\n";	if(Head == NULL)  {		cout << "Nothing in list!\n";		return;	}	item* temp = Head;	while (temp != NULL)	{		cout << temp->name << " " << temp->amount << endl;		temp = temp->next;	}}void KillItem(item** Head){	char get[80];	int a;	cout << "What item would you like to delete? ";	cin.getline(get, sizeof(get));	cin.getline(get, sizeof(get));	cout << "How much of ''" << get << "'' should be deleted? ";	cin >> a;	if(*Head == NULL)	return;	if (strcmp((*Head)->name, get) == 0)	{		item* temp = *Head;		if(a >= temp->amount)		{			*Head = (*Head)->next;			delete temp;			cout << "Item ''" << get << "'' has been deleted\n";		}else{			temp->amount = temp->amount - a;			cout << "Item ''" << get << "'' amount is now " << temp->amount << endl;		}		return;	}	item* temp1 = *Head;	item* temp2 = (*Head)->next;	while(temp2 != NULL)	{		if (strcmp(get, temp2->name) == 0)		{			if(a >= temp2->amount)			{				temp1->next = temp2->next;				delete temp2;				cout << "Item ''" << get << "'' has been deleted\n";			}else{				temp2->amount = temp2->amount - a;				cout << "Item ''" << get << "'' amount is now " << temp2->amount << endl;			}			return;		}		temp2 = temp2->next;		temp1 = temp1->next;	}	cout << "Item ''" << get << "'' was not found!\n";}void KillList(item** Head){	char yn;	cout << "Are you sure you want to delete everything on the list? y/n: ";	cin >> yn;	if(yn == ''n'')	{		return;	} else {		item* temp = NULL;		while(*Head != NULL)		{			temp = *Head;			*Head = (*Head)->next;			delete temp;		}		cout << "List Cleared!\n";	}}void mnu(){	cout << "****************************\n";	cout << "*           List           *\n";	cout << "*1                 Add Item*\n";	cout << "*2               Print List*\n";	cout << "*3              Delete Item*\n";	cout << "*4              Delete List*\n";	cout << "*5                View Menu*\n";	cout << "*6                     Quit*\n";	cout << "****************************\n";}  


Gl I hope this helps.
--------------------------Nukemmsn: nukem996@hotmail.comaim: nukem996open source open mind

This topic is closed to new replies.

Advertisement