Esempio n. 1
0
/***************************************************************
* Function: CodeParser::parseXMLFile()
* Purpose : Parse a an XML IR file
* Initial : Maxime Chevalier-Boisvert on November 18, 2008
****************************************************************
Revisions and bug fixes:
*/
CompUnits CodeParser::parseXMLFile(const std::string& filePath)
{
	// Log that we are parsing this file
	std::cout << "Parsing XML IR file: \"" << filePath << "\"" << std::endl;

	// Create an XML parser object
	XML::Parser parser;

	// Setup a try block to catch any errors
	try
	{
		// Parse the IR code string
		XML::Document xmlIR = parser.parseFile(filePath);

		// If the verbose output flag is set
		if (ConfigManager::s_verboseVar.getBoolValue() == true)
		{
			// Output the parsed XML
			std::cout << std::endl;
			std::cout << "Parsed XML: " << std::endl;
			std::cout << xmlIR.toString() << std::endl;
			std::cout << std::endl;
		}

		// Get a pointer to the XML tree root
		const XML::Element* pTreeRoot = xmlIR.getTree();

		// Parse the XML tree
		return parseXMLRoot(pTreeRoot);
	}

	// If XML parsing error occur
	catch (XML::ParseError error)
	{
		// Log the error
		std::cout << "ERROR: XML parsing failed " + error.toString() << std::endl;

		// Exit this function
		return CompUnits();
	}
}
Esempio n. 2
0
MapInfoLoader::MapInfoLoader( std::string sFileName )
{
	assert( m_sgMapInfoLoader == NULL );
	m_sgMapInfoLoader = this;

	XML::Parser parser;
	XML::Node *mapentries, *document;

	try
	{
		parser.loadData( sFileName );
		document = parser.parseDocument();

		mapentries = document->findNode( "MAPS" );
	}
	catch (...)
	{
		THROWEXCEPTION( "Couldn't find maps.xml" );
	}

	if ( !mapentries )
	{
		THROWEXCEPTION( "Couldn't find maps node." );
	}


	XML::Node *map_node, *value; 

	int idx = 0;

	while ( ( map_node = mapentries->findNode( "MAP", idx ) ) )
	{ 
		int id = map_node->findInteger( "ID" );
		if ( !id )
		{
			id = idx; // default value
		}

		int width = map_node->findInteger( "WIDTH" );;
		int height = map_node->findInteger( "HEIGHT" );
		std::string name = map_node->findString( "NAME" );
		std::string skybox = map_node->findString( "SKYBOX" );

		int base_id = -1;

		if ( ( value = map_node->findNode( "BASE_ID" ) ) )
		{
			base_id = value->asInteger();
		}
		int r = 255, g = 255, b = 255;

		if ( ( value = map_node->findNode( "FOG_COLOR" ) ) )
		{
			value->lookupAttribute( "red", r );
			value->lookupAttribute( "blue", b );
			value->lookupAttribute( "green", g ); 
		}

		cMapInfoEntry *map_entry = new cMapInfoEntry( id, width, height, name, skybox, base_id, r, g, b );
		m_vMaps.insert( std::make_pair( id, map_entry ) );
		idx++;
	}
}
Esempio n. 3
0
bool cGrannyLoader::Load(std::string filename, std::string mulpath)
{
	tick = 0;

	XML::Parser parser;
	XML::Node *granny=NULL, *document=NULL;

	try
	{
		parser.loadData(filename);
		document = parser.parseDocument();

		granny = document->findNode( "GRANNY" );

		if( !granny )
			throw "Couldn't find granny node.";
	}
	catch( ... )
	{
		pDebug.Log ("Couldn't load Granny Definitions");
		return false;
	}

	XML::Node value;

	TiXmlNode *tgranny  = granny->getTinyNode();


	bool ext = false;
	std::string texpath, smdpath;

	if (value = tgranny->FirstChildElement("TEXTUREPATH"))
		texpath = value.asString();

	if (value = tgranny->FirstChildElement("SMDPATH"))
		smdpath = value.asString();

	if (smdpath==".") 
	{
		CString strPath = CFileString::GetModuleDir()+"/";
		strPath.Replace('\\','/');
		mulpath = strPath;
	}
	else if (!smdpath.empty())
	{
		mulpath = smdpath;
	}

	this->mulpath = mulpath;

	if (texpath.find(":/") != std::string::npos || texpath.find(":\\") != std::string::npos)
		tex_basepath = texpath;
	else
		tex_basepath = mulpath + texpath;

	assert(!pGrannyTextureLoader);
	pGrannyTextureLoader = new cGrannyTextureLoader(tex_basepath);

	TiXmlHandle hgranny(granny->getTinyNode());

#if 0
	TiXmlElement *set_node = hgranny.FirstChild("ANIMSET_LIST").FirstChild("ANIMSET").Element();

	while (set_node) 
	{
		InsertAnimset(set_node);

		set_node = set_node->NextSiblingElement(set_node->Value());
	}

	TiXmlElement *char_node = hgranny.FirstChild("CHARACTER_AOS_LIST").FirstChild("CHARACTER_AOS").Element();
	while (char_node) 
	{
		InsertCharacterAOS(char_node);
		
		char_node = char_node->NextSiblingElement(char_node->Value());
	}

	char_node = hgranny.FirstChild("CHARACTER_LIST").FirstChild("CHARACTER").Element();
	while (char_node) 
	{
		InsertCharacter(char_node);
		
		char_node = char_node->NextSiblingElement(char_node->Value());
	}
#else
	TiXmlElement *anim_node = tgranny->FirstChildElement("ANIMSET");
	while (anim_node) 
	{
		InsertAnimset(anim_node);
		anim_node = anim_node->NextSiblingElement("ANIMSET");
	}
	
	TiXmlElement * char_node = tgranny->FirstChildElement();
	while (char_node) 
	{
		if (char_node->ValueStr()=="CHARACTER")
			InsertCharacter(char_node);
		else if (char_node->ValueStr()=="CHARACTER_AOS")
			InsertCharacterAOS(char_node);
		
		char_node = char_node->NextSiblingElement();
	}
#endif
	

	delete document;

	return true;
}
Esempio n. 4
0
MacroLoader::MacroLoader()
{
    XML::Parser parser;
    XML::Node *macroentries, *document;

    try
    {
        parser.loadData( "./xml/Macros.xml" );
        document = parser.parseDocument();

        macroentries = document->findNode( "MACROS" );

        if ( !macroentries )
        {
            throw "Couldn't find macros node.";
        }
    }
    catch( ... )
    {
        Logger::WriteLine( "\t| -> Couldn't load Macros.xml" );
        return;
    }

    XML::Node *macro_node, *value;
    int idx = 0, iMacroCount = 0;

    while ( ( macro_node = macroentries->findNode( "MACRO", idx ) ) )
    {
        int id = idx;
        SDLKey key = (SDLKey)0;
        int keymod = 0x0000;
        std::vector<m_Parameter*> parameters;
        std::string script_function = "none";
        //Logger::WriteLine( "MCR1" );
        iMacroCount++;
        value = macro_node->findNode( "ID" );

        id = ( value != NULL ) ? value->asInteger() : idx;

        if ( ( value = macro_node->findNode( "KEY" ) ) )
        {
            key = getkey_byname(value->asString());
        }

        if ( ( value = macro_node->findNode( "LEFT_SHIFT" ) ) )
        {
            if ( value->asInteger() == 1 )
            {
                keymod |= KMOD_LSHIFT;
            }
        }
        if ( ( value = macro_node->findNode( "RIGHT_SHIFT" ) ) )
        {
            if ( value->asInteger() == 1 )
            {
                keymod |= KMOD_RSHIFT;
            }
        }
        if ( ( value = macro_node->findNode( "RIGHT_ALT" ) ) )
        {
            if ( value->asInteger() == 1 )
            {
                keymod |= KMOD_RALT;
            }
        }
        if ( ( value = macro_node->findNode( "LEFT_ALT" ) ) )
        {
            if ( value->asInteger() == 1 )
            {
                keymod |= KMOD_LALT;
            }
        }
        if ( ( value = macro_node->findNode( "RIGHT_CONTROL" ) ) )
        {
            if ( value->asInteger() == 1 )
            {
                keymod |= KMOD_RCTRL;
            }
        }
        if ( ( value = macro_node->findNode( "LEFT_CONTROL" ) ) )
        {
            if ( value->asInteger() == 1 )
            {
                keymod |= KMOD_LCTRL;
            }
        }
        if ( ( value = macro_node->findNode( "SCRIPT_FUNCTION" ) ) )
        {
            script_function = value->asString();
        }
        std::string parameter_type;

        int idx2 = 0;
        while ( ( value = macro_node->findNode( "PARAMETER", idx2 ) ) )
        {
            m_Parameter * param = NULL;
            if ( value->lookupAttribute( "TYPE", parameter_type ) )
            {
                // std::cout << "PARAMETER" << parameter_type << std::endl;
                param = new m_Parameter();
                if ( parameter_type == "string" )
                {
                    param->type = PARAMETERTYPE_STRING;
                    param->str_value = value->asString();
                    param->int_value = 0;
                }
                else if ( parameter_type == "integer" )
                {
                    param->type = PARAMETERTYPE_INTEGER;
                    param->str_value = "";
                    param->int_value = IRIS_SwapI32(value->asInteger());
                }
                else
                {
                    Logger::WriteLine("Warning: Macros.xml: wrong parameter type, skipping...");
                    continue;
                }
            }
            else
            {
                Logger::WriteLine("Warning: Macros.xml: no parameter type specified, skipping...");
                continue;
            }
            if ( parameters.size() < 5 )
            {
                parameters.push_back(param);
            }
            idx2++;
        }
        MacroEntry * entry = new MacroEntry();
        entry->id = IRIS_SwapI32(id);
        entry->key = key;
        entry->keymod = (SDLMod)keymod;
        entry->script_function = script_function;
        entry->parameters = parameters;
        macros.insert( std::make_pair( (int)key, entry ) );
        idx++;
    }
    char cMacros[2];
    sprintf( cMacros, "%d", iMacroCount );
    Logger::WriteLine( "\t| -> Sucessfuly loaded " + std::string( cMacros ) );
}
Esempio n. 5
0
ZString api_gui_addform( ZCsl *aCsl )
{
	clear_controlid_list();

	int argCount = aCsl->get("argCount").asInt();
//	int flags = GUMPFLAG_MOVABLE | GUMPFLAG_CLOSABLE | GUMPFLAG_FOCUSABLE;
	int x = aCsl->get("x").asInt();
	int y = aCsl->get("y").asInt();
	std::string gfm_file = std::string (aCsl->get("gfm_file").buffer ());
	bool is_container = (argCount > 3) ? ((int) aCsl->get("is_container").asInt()) : false;

	Container* container = NULL;
	std::string shape;
	
	XML::Parser parser;
	XML::Node* form=NULL,* document=NULL;
	
	try
	{
		parser.loadData(gfm_file);
		document = parser.parseDocument();

		int width=640,height=480, alpha=0, flags=0, fade_alpha=0, fade_time=0;
		
		std::string onclick, onclose, onmouseup, onmousedown, onkeypressed;
		
		form = document->findNode("form");
		if ( !form )
		{
			throw;
		}
		
		form->lookupAttribute("width", width);
		form->lookupAttribute("height", height);
		form->lookupAttribute("alpha", alpha);
		form->lookupAttribute("flags", flags);
		form->lookupAttribute("shape", shape);

		XML::Node* fade_node = form->findNode("fade");
		if (fade_node)
		{
			fade_node->lookupAttribute("alpha", fade_alpha);
			fade_node->lookupAttribute("time", fade_time);
		}

		XML::Node* event_node = form->findNode("event");

		if (event_node)
		{
			event_node->lookupAttribute("onclick", onclick);
			event_node->lookupAttribute("onclose", onclose);
			event_node->lookupAttribute("onmouseup", onmouseup);
			event_node->lookupAttribute("onmousedown", onmousedown);
			event_node->lookupAttribute("onkeypressed", onkeypressed);
		}	

		if (is_container)
		{
			container = new Container();
			container->SetPosition(x,y);
			container->SetSize(width, height);
			container->SetAlpha(alpha);
			if (fade_time != 0) 
				container->FadeTo(fade_alpha, fade_time);

			x = 0, y = 0;
			
			api_addcontrol( container );

			Control* control=container;
			if (!onclose.empty()) {
				control->OnClose(on_closehandler);
				control->SetScriptFunction(FUNC_ONCLOSE, (char*)onclose.c_str());
			}
			if (!onmousedown.empty()) {
				control->OnMouseDown(on_mousedownhandler);
				control->SetScriptFunction(FUNC_ONMOUSEDOWN, (char*)onmousedown.c_str());
			}
			if (!onmouseup.empty()) {
				control->OnMouseUp(on_mouseuphandler);
				control->SetScriptFunction(FUNC_ONMOUSEUP, (char*)onmouseup.c_str());
			}

			act_container_id = container->GetID();
		}
	} catch (...) {
		//delete document;
		return "0";
	}

	int idx=0;
	XML::Node* control_node = NULL;			
	
	while ((control_node = form->findNode("control", idx++))) {
		Control* control=NULL;
		XML::Node* event_node=NULL,* gump_node=NULL, * passwd_node=NULL;
		XML::Node* check_node=NULL,* group_node=NULL,* text_node=NULL;
		
		std::string type, name;
		std::string onclick, onclose, onmouseup, onmousedown, onkeypressed;

		int left=0,top=0,width=0,height=0,freezed=0,visible=1;			
		int alpha=0,flags=0;

		if (!control_node->lookupAttribute("class", type)) continue;

		control_node->lookupAttribute("name", name);
		control_node->lookupAttribute("left", left);
		control_node->lookupAttribute("top", top);
		control_node->lookupAttribute("width", width);
		control_node->lookupAttribute("height", height);
		control_node->lookupAttribute("freezed", freezed);
		control_node->lookupAttribute("visible", visible);
		control_node->lookupAttribute("alpha", alpha);
		control_node->lookupAttribute("flags", flags);

		left+=x;
		top+=y;

		if ((event_node = control_node->findNode("event"))) {
			event_node->lookupAttribute("onclick", onclick);
			event_node->lookupAttribute("onclose", onclose);
			event_node->lookupAttribute("onmouseup", onmouseup);
			event_node->lookupAttribute("onmousedown", onmousedown);
			event_node->lookupAttribute("onkeypressed", onkeypressed);
		}	
		
		if (type=="picture" || type=="border" || type=="paperdoll") {			
			int gump=0;
			if ((gump_node = control_node->findNode("gump"))) 
				gump = gump_node->asInteger();

			//int flags = GUMPFLAG_MOVABLE | GUMPFLAG_CLOSABLE | GUMPFLAG_FOCUSABLE;
			
			if (type=="picture") {
				control = new Image(left, top, gump, flags);
			} else if (type=="border") {
				control = new Border(left,top, gump, flags);
			} else {
				control = new Paperdoll(left, top, 0);
			}
			control->SetSize(width, height);
			
		} else if (type=="button") {
			int normal=-1, over=-1, pressed=-1;
			if ((gump_node = control_node->findNode("gump"))) { 
				gump_node->lookupAttribute("normal", normal);
				gump_node->lookupAttribute("over", over);
				gump_node->lookupAttribute("pressed", pressed);
			}

			//Button *button = new Button(left,top);
			
			
			/*if (normal >= 0) button->SetButton(BUTTONGUMP_NORMAL, normal);
			if (over >= 0) button->SetButton(BUTTONGUMP_MOUSEOVER, over);
			if (pressed >= 0) button->SetButton(BUTTONGUMP_PRESSED, pressed);*/
			control = new Button( left, top );

			if (normal >= 0)
				((Button*)control)->SetButton(BUTTONGUMP_NORMAL, normal);
			if (over >= 0)
				((Button*)control)->SetButton(BUTTONGUMP_MOUSEOVER, over);
			if (pressed >= 0)
				((Button*)control)->SetButton(BUTTONGUMP_PRESSED, pressed);

			if (!onclick.empty()) {
				/*button->OnClick(on_clickhandler);
				button->SetScriptFunction(FUNC_ONCLICK, (char*)onclick.c_str());*/
				((Button*)control)->OnClick(on_clickhandler);
				((Button*)control)->SetScriptFunction(FUNC_ONCLICK, (char*)onclick.c_str());
			}
			
			//control = button;
		} else if (type=="checkbox" || type=="radio") {
			int normal=-1, checked=-1, group=0, ischecked=0;
			gump_node = control_node->findNode("gump");
			if (gump_node) { 
				gump_node->lookupAttribute("normal", normal);
				gump_node->lookupAttribute("checked", checked);
			}
			if ((check_node = control_node->findNode("checked"))) {
				ischecked = check_node->asBool();
			}
			if ((group_node = control_node->findNode("group"))) {
				group = group_node->asInteger();
			}
		} else if (type=="label" || type=="edit") {
			std::string text, align;
			int font=-1,hue=-1,password=0, label_align=-1;
			if ((text_node = control_node->findNode("text"))) {
				text = text_node->asString();
				text_node->lookupAttribute("font", font);
				text_node->lookupAttribute("hue", hue);
				text_node->lookupAttribute("align", align);
			}

			if ((passwd_node = control_node->findNode("password"))) {
				password = passwd_node->asBool();
			}
			
			if (type == "label") {
				if (align=="center") {
					label_align=1;
					left += width / 2;
					//top  += height / 2;
				} else if (align=="right") {
					label_align=2;
					left += width;
					//top  += height;
				}

				Label* label = new Label(left, top, text.c_str(), hue, font);
/*SiENcE:
				if (font >= 0) label->setFont(font);
				if (hue >= 0) label->setHue(hue);
*/
				if (label_align >= 0) label->setAlign(label_align);
					control = label;
				}
				else
				{
					font = font < 0 ? 3 : font;
					hue = hue < 0 ? 0 : hue;
					InputField *input = new InputField(left,top,width,height, text.c_str(), hue, font, password ? 42 : 0);
					input->OnKeyPress(on_keypressedhandler);
					if (!onkeypressed.empty())
						input->SetScriptFunction(FUNC_ONKEYPRESSED, (char*)onkeypressed.c_str());
					control = input;
				}
		}

		if ( !control )
		{
			continue;
		}

		api_addcontrol(control);

		add_controlid(name,control->GetID());

		if (!onclose.empty()) {
			control->OnClose(on_closehandler);
			control->SetScriptFunction(FUNC_ONCLOSE, (char*)onclose.c_str());
		}
		if (!onmousedown.empty()) {
			control->OnMouseDown(on_mousedownhandler);
			control->SetScriptFunction(FUNC_ONMOUSEDOWN, (char*)onmousedown.c_str());
		}
		if (!onmouseup.empty()) {
			control->OnMouseUp(on_mouseuphandler);
			control->SetScriptFunction(FUNC_ONMOUSEUP, (char*)onmouseup.c_str());
		}
	}

	document = NULL;

	if ( container )
	{
		if ( !shape.empty() )
		{
			container->SetShape( get_controlid( shape ) );
		}
		act_container_id = 0;
		return ZString( container->GetID() );
	}

	return "0";
}
BOOL CGumpEditorDoc::OnOpenDocument(LPCTSTR lpszPathName)
{
	XML::Parser parser;
	XML::Node* form=NULL,* document=NULL;
	XML::Node* section = NULL,* value = NULL;
	CSize sizeForm(m_iDefWidth,m_iDefHeight);
	
	try	{
		parser.loadData(lpszPathName);
		document = parser.parseDocument();

		form = document->findNode("form");
		if(!form ) throw;
		form->lookupAttribute("width",  (int&)sizeForm.cx);
		form->lookupAttribute("height", (int&)sizeForm.cy);

		int alpha=0,flags=0;
		std::string shape;

		form->lookupAttribute("alpha", alpha);
		form->lookupAttribute("flags", flags);
		form->lookupAttribute("shape", shape);

		m_objs.Clear();
		m_objs.SetVirtualSize(sizeForm);

		SetAlpha(alpha);
		SetFlags(flags);
		SetShapeName(shape.c_str());
	} catch (...) {
		return FALSE;
	}

	
	int alpha=0,time=0;
	std::string onclick, onclose, onmouseup, onmousedown, onkeypressed;
	
	XML::Node* fade_node = form->findNode("fade");
	if (fade_node) {
		fade_node->lookupAttribute("alpha", alpha);
		fade_node->lookupAttribute("time", time);
	}

	XML::Node* event_node = form->findNode("event");
	if (event_node) {
		event_node->lookupAttribute("onclick", onclick);
		event_node->lookupAttribute("onclose", onclose);
		event_node->lookupAttribute("onmouseup", onmouseup);
		event_node->lookupAttribute("onmousedown", onmousedown);
		event_node->lookupAttribute("onkeypressed", onkeypressed);
	}

	SetFade(alpha, time);
	SetEventHandler(onclick.c_str(), onclose.c_str(), onmouseup.c_str(), onmousedown.c_str(), onkeypressed.c_str());

	int idx=0;
	XML::Node* control = NULL;	

	while (control = form->findNode("control", idx++)) {
		CDiagramEntity* obj = CDiagramControlFactory::CreateFromString(control);
		if (obj) m_objs.Add(obj);
	}
	
	m_objs.SetModified( FALSE );
	
	delete document; document=NULL;

	return TRUE;
}
Esempio n. 7
0
cGrannyLoader::cGrannyLoader( string filename, string mulpath )
{
	this->mulpath = mulpath;
	tick = 0;

	XML::Parser parser;
	XML::Node *granny, *document;

	try
	{
		parser.loadData( filename );
		document = parser.parseDocument();

		granny = document->findNode( "GRANNY" );

		if ( !granny )
		{
			throw "Couldn't find granny node.";
		}
	}
	catch (...)
	{
		Logger::WriteLine( "Couldn't load Granny Definitions" );
		return;
	}

	XML::Node *char_node, *set_node, *value;

	if ( (value = granny->findNode( "TEXTUREPATH" ) ) )
	{
		tex_basepath = mulpath + value->asString();
	}

	assert( !pGrannyTextureLoader );
	pGrannyTextureLoader = new cGrannyTextureLoader( tex_basepath );

	std::map<int, cAnimSet *> animsets;
	std::map<int, cAnimSet *>::iterator iter;
	std::map<int, string>::iterator name_iter;


	int idx = 0;
	while ( (set_node = granny->findNode("ANIMSET", idx)) )
	{
		cAnimSet *animset = new cAnimSet();
		value = set_node->findNode( "ID" );
		animset->id = (value != NULL) ? value->asInteger() : 0;
		if ( ( value = set_node->findNode( "DEFAULTANIM" )) )
		{
			animset->defaultanim = mulpath + to_lower( value->asString() );
		}

		int idx2 = 0;
		XML::Node *anim_node;
		while ( (anim_node = set_node->findNode( "ANIMATION", idx2 )) )
		{
			std::string animtype = "", filename = "";
			if ( (value = anim_node->findNode( "TYPE" )) )
			{
				animtype = value->asString();
			}
			if ( (value = anim_node->findNode ("FILE")) )
			{
				filename = mulpath + to_lower( value->asString() );
			}

			int anim_typeid = -1;
			for ( int i = 0; TypeInfo[i].blockid != -1; i++ )
			{
				const TypeData &Data = TypeInfo[i];
				if ( Data.name == animtype )
				{
					anim_typeid = Data.blockid;
				}
			}

			if ( anim_typeid != -1 )
			{
				animset->anim_names.insert( std::make_pair( anim_typeid, filename ) );
			}

			idx2++;
		}

		//animsets.erase(animset->id);
		animsets.insert( std::make_pair( animset->id, animset ) );

		idx++;
	}

	idx = 0;
	while ((char_node = granny->findNode ("CHARACTER", idx)))
	{
		std::string filename = "", default_anim = "", prefix = "";
		int left_hand_bone = -1;
		int right_hand_bone = -1;
		int animset = -1;
		int hand = HAND_NONE;

		value = char_node->findNode ("ID");
		Uint32 id = (value != NULL) ? value->asInteger () : 0;
		if ((value = char_node->findNode ("FILE")))
			filename = mulpath + to_lower (value->asString ());
		if ((value = char_node->findNode ("ANIMSET")))
			animset = value->asInteger ();
		if ((value = char_node->findNode ("PREFIX")))
			prefix = to_lower (value->asString ());

		if ((value = char_node->findNode ("LEFT_HAND_BONE")))
		{
			left_hand_bone = value->asInteger ();
			hand = HAND_OWNER;
		}
		if ((value = char_node->findNode ("RIGHT_HAND_BONE")))
		{
			right_hand_bone = value->asInteger ();
			hand = HAND_OWNER;
		}

		if ((value = char_node->findNode ("HAND")))
		{
			if (value->asString () == "left")
				hand = HAND_LEFT;
			if (value->asString () == "right")
				hand = HAND_RIGHT;
		}

		Uint16 assign = 0;
		if ((value = char_node->findNode ("ASSIGN")))
			assign = value->asInteger ();

		//SiENcE: if female id-1000, to show female clothes
		// (i dont know why it needs a subtract of 1000!, ids are correct)
		//if (assign == 401) id=id-1000;

		//HARKON: recevied clothes id is equals male/female(runuo 1.0). but weapon isn't equals.
		// examples, ganny_aos.xml male kilt id is 455, female kilt id is 1455. server only sends 455.
		if (assign == 401 && hand == HAND_NONE) id -= 1000;

		id |= assign << 16;      
		iter = animsets.find (animset);

		if (id && (iter != animsets.end ()))
		{
			assert (iter->second);
			cGrannyModel *model = new cGrannyModelTD( filename, tex_basepath, iter->second->defaultanim, prefix );
			model->SetHandBones( left_hand_bone, right_hand_bone );
			model->SetHand( hand );
			model->SetAnimset( animset );
			for ( name_iter=iter->second->anim_names.begin(); name_iter != iter->second->anim_names.end(); name_iter++ )
			{
				model->AddAnimation( name_iter->first, name_iter->second );
			}

			//models.erase(id);
			if ( models.find( id ) != models.end() )
			{
				//Logger::WriteLine("Warning: duplicated model id : %d", id);
				SAFE_DELETE( models.find( id )->second );
				models.erase( id );
			}
			models.insert( make_pair( id, model ) );
		}
		else
		{
			Logger::WriteLine ("Warning: Invalid Granny Definition");
		}

		idx++;
	}

	idx = 0;
	while ((char_node = granny->findNode ("CHARACTER_AOS", idx)))
	{
		std::string filename = "", default_anim = "";
		int animset = -1;

		int left_hand_bone = -1;
		int right_hand_bone = -1;
		int hand = HAND_NONE;

		value = char_node->findNode ("ID");
		Uint32 id = (value != NULL) ? value->asInteger () : 0;
		if ((value = char_node->findNode ("ANIMSET")))
			animset = value->asInteger ();

		if ((value = char_node->findNode ("LEFT_HAND_BONE")))
		{
			left_hand_bone = value->asInteger ();
			hand = HAND_OWNER;
		}
		if ((value = char_node->findNode ("RIGHT_HAND_BONE")))
		{
			right_hand_bone = value->asInteger ();
			hand = HAND_OWNER;
		}

		Uint16 assign = 0;
		if ((value = char_node->findNode ("ASSIGN")))
			assign = value->asInteger ();
		id |= assign << 16;

		iter = animsets.find (animset);

		if ( id && ( iter != animsets.end() ) )
		{
			assert (iter->second);
			cGrannyModelAOS *model = new cGrannyModelAOS (tex_basepath, iter->second->defaultanim);

			model->SetHandBones (left_hand_bone, right_hand_bone);
			model->SetHand (hand);

			model->SetAnimset (animset);
			for (int i = 0; AOSBodyInfo[i].id != 0; i++)
			{
				const AOSBodyData &Data = AOSBodyInfo[i];
				XML::Node *submodel = char_node->findNode (Data.name);
				if ( submodel )
				{
					model->AddModel( i, mulpath + to_lower( submodel->asString() ) );
				}
			}

			for ( name_iter = iter->second->anim_names.begin(); name_iter != iter->second->anim_names.end(); name_iter++ )
			{
				model->AddAnimation( name_iter->first, name_iter->second );
			}

			//models.erase(id);
			if ( models.find( id ) != models.end() )
			{
				//Logger::WriteLine("Warning: duplicated model id : %d\n", id);
				SAFE_DELETE( models.find( id )->second );
				models.erase( id );
			}
			models.insert( std::make_pair( id, model ) );

		}
		else
		{
			Logger::WriteLine ("Warning: Invalid Granny AOS Definition");
		}

		idx++;
	}

	for ( iter = animsets.begin(); iter != animsets.end(); iter++ )
	{
		SAFE_DELETE( iter->second );
	}
	animsets.clear();

	//delete document;
}
Esempio n. 8
0
bool Config::Init()
{
	// Default values, if they are not set under config.xml those will be used.
	// Section GFX
	m_vParserInfo.push_back( ParserData( "GFX", IS_SECTION, NULL ) );
	m_vParserInfo.push_back( ParserData( "WIDTH", IS_INTEGER, &m_iWidth ) );
	m_vParserInfo.push_back( ParserData( "HEIGHT", IS_INTEGER, &m_iHeight ) );
	m_vParserInfo.push_back( ParserData( "BPP", IS_INTEGER, &m_iBPP ) );
	m_vParserInfo.push_back( ParserData( "CURSOR", IS_INTEGER, &m_iCursor ) );
	m_vParserInfo.push_back( ParserData( "PERSPECTIVE", IS_INTEGER, &m_iPerspective ) );
	m_vParserInfo.push_back( ParserData( "FULLSCREEN", IS_INTEGER, &m_iStartFullScreen ) );
	m_vParserInfo.push_back( ParserData( "ROOF_FADE_TIME", IS_INTEGER, &m_iRoofFadeTime ) );
	m_vParserInfo.push_back( ParserData( "ROOF_FADE_ALPHA", IS_INTEGER, &m_iRoofFadeAlpha ) );
	m_vParserInfo.push_back( ParserData( "ZBUFFER_SIZE", IS_INTEGER, &m_iDepthBuffer ) );
	m_vParserInfo.push_back( ParserData( "MAXZOOM", IS_INTEGER, &m_iMaxZoom ) );
	m_vParserInfo.push_back( ParserData( "MAXANGLE", IS_INTEGER, &m_iMaxAngle ) );
	m_vParserInfo.push_back( ParserData( "VIEWDISTANCE", IS_INTEGER, &m_iViewDistance ) );
	m_vParserInfo.push_back( ParserData( "BRIGHTNESS", IS_INTEGER, &m_iBrightness ) );

	// Section UO
	m_vParserInfo.push_back( ParserData( "UO", IS_SECTION, NULL ) );
	m_vParserInfo.push_back( ParserData( "STARTX", IS_INTEGER, &m_iStartX ) );
	m_vParserInfo.push_back( ParserData( "STARTY", IS_INTEGER, &m_iStartY ) );
	m_vParserInfo.push_back( ParserData( "STARTZ", IS_INTEGER, &m_iStartZ ) );
	m_vParserInfo.push_back( ParserData( "MULPATH", IS_STRING, &m_sMulPath ) );
	// m_vParserInfo.push_back( ParserData( "COMPRESSED_MAP", IS_STRING, &m_sCompressedMap ) );
	m_vParserInfo.push_back( ParserData( "POPUP_MENU", IS_INTEGER, &m_iPopup ) );
	m_vParserInfo.push_back( ParserData( "AOS", IS_INTEGER, &m_iAOSToolTips ) );
	m_vParserInfo.push_back( ParserData( "CLIENT_IDENTIFICATION", IS_STRING, &m_sClientVersion ) );
	m_vParserInfo.push_back( ParserData( "USE_CLILOCS", IS_INTEGER, &m_iClilocs ) );
	m_vParserInfo.push_back( ParserData( "CLILOC_LANGUAGE", IS_STRING, &m_sClilocLang ) );
	m_vParserInfo.push_back( ParserData( "SPEECH_HUE", IS_INTEGER, &m_iSpeechHue ) );
	m_vParserInfo.push_back( ParserData( "AOSTOOLTIPS", IS_INTEGER, &m_iAOSToolTips ) );
    //Artix added speech.mul config option
    m_vParserInfo.push_back( ParserData( "USE_SPEECH", IS_INTEGER, &m_iSpeech ) );
	// Section NET
	m_vParserInfo.push_back( ParserData( "NET", IS_SECTION, NULL ) );
	m_vParserInfo.push_back( ParserData( "PORT", IS_INTEGER, &m_iServerPort ) );
	m_vParserInfo.push_back( ParserData( "SERVER", IS_STRING, &m_sServer ) );
	m_vParserInfo.push_back( ParserData( "LOGIN", IS_STRING, &m_sLogin ) );
	m_vParserInfo.push_back( ParserData( "PASSWORD", IS_STRING, &m_sPassword ) );
	m_vParserInfo.push_back( ParserData( "IS_SPHERE", IS_INTEGER, &m_iIsSphere ) );
	m_vParserInfo.push_back( ParserData( "IS_SPHERE55R", IS_INTEGER, &m_iIsSphere55R ) );
	m_vParserInfo.push_back( ParserData( "IS_POL", IS_INTEGER, &m_iIsPol ) );
	m_vParserInfo.push_back( ParserData( "IS_RUNUO", IS_INTEGER, &m_iIsRunUO ) );
	m_vParserInfo.push_back( ParserData( "IS_UOX3", IS_INTEGER, &m_iIsUox3 ) );
	m_vParserInfo.push_back( ParserData( "CLIENT_KEY", IS_INTEGER, &m_iClientKey ) );

	// Section Sound
	m_vParserInfo.push_back( ParserData( "SOUND", IS_SECTION, NULL ) );
	m_vParserInfo.push_back( ParserData( "MUSIC", IS_INTEGER, &m_iMusic ) );
	m_vParserInfo.push_back( ParserData( "SOUND", IS_INTEGER, &m_iSound ) );
	m_vParserInfo.push_back( ParserData( "FREQUENCY", IS_INTEGER, &m_iFrequency ) );
	m_vParserInfo.push_back( ParserData( "STEREO", IS_INTEGER, &m_iStereo ) );
	m_vParserInfo.push_back( ParserData( "CHUNKSIZE", IS_INTEGER, &m_iChunkSize ) );
	m_vParserInfo.push_back( ParserData( "MUSICVOLUME", IS_INTEGER, &m_iMusicVolume ) );
	m_vParserInfo.push_back( ParserData( "SOUNDVOLUME", IS_INTEGER, &m_iSoundVolume ) );
	m_vParserInfo.push_back( ParserData( "MP3", IS_INTEGER, &m_iMP3 ) );
	m_vParserInfo.push_back( ParserData( "FOOTSTEPS", IS_INTEGER, &m_iFootSteps ) );

	// Section Iris Client
	m_vParserInfo.push_back( ParserData( "IRIS", IS_SECTION, NULL ) );
	m_vParserInfo.push_back( ParserData( "SCRIPTS_PATH", IS_STRING, &m_sScriptPath ) );
	m_vParserInfo.push_back( ParserData( "MOUSEOVER_TIMER", IS_INTEGER, &m_iMouseMotionTimer ) );
	m_vParserInfo.push_back( ParserData( "", IS_END, NULL ) );


	// After adding to the vector our struct start filling it with actual values
	XML::Parser kParser;

	kParser.loadData( "./xml/config.xml" );
	XML::Node *kDocument = kParser.parseDocument();
	XML::Node *kConfig = kDocument->findNode( "CONFIG" );

	if ( !kConfig )
	{
		THROWEXCEPTION( "Could not find configuration node." );

		return false;
	}

	XML::Node *kValue = NULL, *kSection = NULL;
	// Read all values from config.xml
	for ( int i = 0; m_vParserInfo[i].iType != IS_END; i++ )
	{
		const ParserData &Data = m_vParserInfo[i];

		if ( Data.iType == IS_SECTION )
		{
			kSection = kConfig->findNode( Data.sName );
		}
		else
		{
			// If no section is loaded get from <config>
			kValue = kSection != NULL ? kSection->findNode( Data.sName ) : kConfig->findNode( Data.sName );

			if ( kValue != NULL )
			{
				if ( Data.iType == IS_BOOL )
				{
					*reinterpret_cast<bool *>( Data.pData ) = kValue->asBool();
				}
				else if ( Data.iType == IS_INTEGER )
				{
					*reinterpret_cast<int *>( Data.pData ) = kValue->asInteger();
				}
				else if ( Data.iType == IS_STRING )
				{
					*reinterpret_cast<std::string *>( Data.pData ) = kValue->asString();
				}
			}
		}
	}


	// Read Fonts bit of the file
	XML::Node *kFontSet = kConfig->findNode( "FONTSET" );

	if ( kFontSet )
	{
		int idx = 0;
		XML::Node *kFontNode = NULL;
		FontInfo kFontInfo;

		while ( ( kFontNode = kFontSet->findNode( "FONT", idx++ ) ) )
		{
			if ( !kFontNode->lookupAttribute( "ID", kFontInfo.iId ) )
			{
				continue;
			}

			if ( !kFontNode->lookupAttribute( "FILE", kFontInfo.sFileName ) )
			{
				continue;
			}

			if ( !kFontNode->lookupAttribute( "NAME", kFontInfo.sFontName ) )
			{
				continue;
			}

			if ( !kFontNode->lookupAttribute( "SIZE", kFontInfo.iSize ) )
			{
				continue;
			}

			if ( !kFontNode->lookupAttribute( "HUE",  kFontInfo.iHue ) )
			{
				continue;
			}

			FontManager::GetInstance()->AddTTFFont( kFontInfo.iId, kFontInfo.sFileName, kFontInfo.sFontName, kFontInfo.iSize, kFontInfo.iHue );
		}
	}


	// Depth Buffer
	if ( m_iDepthBuffer <= 0 )
	{
		m_iDepthBuffer = 16;
	}

	// View Distance
	if ( m_iViewDistance < 3 )
	{
		m_iViewDistance = 3;
	}

	// Max Zoom
	if ( m_iMaxZoom <= 0 )
	{
		m_iMaxZoom = 0;
	}

	// Max Angle
	if ( m_iMaxAngle < 10 )
	{
		m_iMaxAngle = 10;
	}

	// Max Angle
	if ( m_iMaxAngle > 90 )
	{
		m_iMaxAngle = 90;
	}

	// Fix Mul path if no / at the end
	if ( m_sMulPath.size() )
	{
		char cLastChar = m_sMulPath[m_sMulPath.length() - 1];

		if ( ( cLastChar != '/' ) && ( cLastChar != '\\' ) )
		{
			m_sMulPath += "/";
		}
	}

	return true;
}