Ejemplo n.º 1
0
//===================================================================================
void CReflectSystem::registerClass(const std::string &className, const std::string &parentName, const TReflectedProperties properties)
{
	if(!_ClassMap)	_ClassMap= new TClassMap;

	TClassMap::const_iterator it = _ClassMap->find(className);
	if (it != _ClassMap->end())
	{
		nlerror("CReflectSystem::registerClass : Class registered twice : %s!", className.c_str());
	}
	CClassInfo &ci = (*_ClassMap)[className];
	ci.Properties = properties;
	ci.ClassName = className;
	for(uint k = 0; k < ci.Properties.size(); ++k)
	{
		ci.Properties[k].ParentClass = &ci;
	}
	if (parentName.empty())
	{
		ci.ParentClass = NULL;
	}
	else
	{
		it = _ClassMap->find(parentName);
		if (it == _ClassMap->end())
		{
			nlerror("CReflectSystem::registerClass : Parent class %s not found", parentName.c_str());
		}
		ci.ParentClass = &(it->second);
	}
}
Ejemplo n.º 2
0
void CActionFactory::registerAction (uint32 code, CAction *(*creator)())
{
/*
	CRegisteredAction::iterator it = RegisteredAction.find (code);
	if (it != RegisteredAction.end ())
	{
		nlerror ("the code %u already registered in the CActionFactory", code);
	}

	RegisteredAction.insert (CRegisteredAction::value_type(code, creator));
*/

	if (RegisteredAction.size() > code && RegisteredAction[code].first != NULL)
	{
		nlerror ("The code %u already registered in the CActionFactory", code);
	}

	if (code >= 256)
	{
		nlerror ("Cannot register action code %d because it exceeds 255", code);
	}

	if (RegisteredAction.size() <= code)
		RegisteredAction.resize(code+1, make_pair((CAction *(*)())NULL, vector<CAction*>()));

	RegisteredAction[code].first = creator;
}
Ejemplo n.º 3
0
void COXml::serialSeparatedBufferOut( const char *value )
{
	nlassert( ! isReading() );

	// Output stream has been setuped ?
	if ( _InternalStream )
	{
		// Current node presents ?
		if (_CurrentNode)
		{
			// Write a push attribute ?
			if (_PushBegin)
			{
				// Current attrib is set ?
				if (_AttribPresent)
				{
					// Set the attribute
					xmlSetProp (_CurrentNode, (const xmlChar*)_AttribName.c_str(), (const xmlChar*)value);

					// The attribute has been used
					_AttribPresent = false;
				}
				else
				{
					// * Error, the stream don't use XML streaming properly
					// * You must take care of this in your last serial call:
					// * - Between xmlPushBegin() and xmlPushEnd(), before each serial, you must set the attribute name with xmlSetAttrib.
					// * - Between xmlPushBegin() and xmlPushEnd(), you must serial only basic objects (numbers and strings).
					nlerror ( "Error, the stream don't use XML streaming properly" );
				}
			}
			else
			{
				// Get the content buffer size
				uint size=(uint)_ContentString.length();

				// Add a separator
				if ((size) && (_ContentString[size-1]!='\n'))
					_ContentString += SEPARATOR;

				// Concat the strings
				_ContentString += value;
			}
		}
		else
		{
			// * Error, no current node present.
			// * Check that your serial is initialy made between a xmlPushBegin and xmlPushEnd calls.
			nlerror ( "Error, the stream don't use XML streaming properly" );
		}
	}
	else
	{
		nlerror ( "Output stream has not been setuped" );
	}
}
bool CCallbackClient::replaySystemCallbacks()
{
	do
	{
		if ( _MR_Recorder.ReceivedMessages.empty() )
		{
			return false;
		}
		else
		{
			switch( _MR_Recorder.ReceivedMessages.front().Event )
			{
			case Receiving:
				return true;

			case Disconnecting:
				LNETL3_DEBUG( "LNETL3C: Disconnection event" );
				_BufSock->setConnectedState( false );

				// Call callback if needed
				if ( disconnectionCallback() != NULL )
				{
					disconnectionCallback()( id(), argOfDisconnectionCallback() );
				}
				break;

			default:
				nlerror( "LNETL3C: Invalid system event type in client receive queue" );
			}
			// Extract system event
			_MR_Recorder.ReceivedMessages.pop();
		}
	}
	while ( true );
}
Ejemplo n.º 5
0
int main(int /* argc */, char ** /* argv */)
{
	// all debug functions have different behaviors in debug and in release mode.
	// in general, in debug mode, all debug functions are active, they display
	// what happens and some break the program to debug it. In release mode, they often
	// do nothing to increase the execution speed.


	// this function initializes debug functions. it adds displayers into the debug
	// logger.
	// in debug mode, all debug functions display on the std output.
	// in release mode, this function does nothing by default. you have to add a displayer
	// manually, or put true in the parameter to say to the function that you want it to
	// add the default displayers
	NLMISC::createDebug();

	// enable the crash report tool
	NLMISC::INelContext::getInstance().setWindowedApplication(true);
	NLMISC::setReportPostUrl("http://ryzomcore.org/crash_report/");

	// display debug information, that will be skipped in release mode.
	nldebug("nldebug() %d", 1);

	// display the string
	nlinfo("nlinfo() %d", 2);

	// when something not normal, but that the program can manage, occurs, call nlwarning()
	nlwarning("nlwarning() %d", 3);

	// nlassert() is like assert but do more powerful things. in release mode, the test is
	// not executed and nothing will happen. (Press F5 in Visual C++ to continue the execution)
	nlassert(true == false);

	// in a switch case or when you want that the program never executes a part of code, use stop.
	// in release, nlstop does nothing. in debug mode,
	// if the code reaches the nlstop, a breakpoint will be set. (In Visual C++ press F5 to continue)
	nlstop;

	// when the program failed, call nlerror(), it displays the message and throws a EFatalError to
	// exit the program. don't forget to put a try/catch block everywhere an nlerror could
	// occurs. (In Visual C++ press F5 to continue)
	try
	{
		nlerror("nlerror() %d", 4);
	}
	catch (const NLMISC::EFatalError &)
	{
		// just continue...
		nlinfo("nlerror() generated an EFatalError exception, just ignore it");
	}

	// keep repeating the same error
	for (int i = 0; i < 32; ++i)
		repeatederror();

	printf("\nPress <return> to exit\n");
	getchar();

	return EXIT_SUCCESS;
}
Ejemplo n.º 6
0
std::string getAppBundlePath()
{
	static std::string cachedPathToBundle;

	if(cachedPathToBundle.size())
		return cachedPathToBundle;

#if defined(NL_OS_MAC)
	// get the bundle
	CFBundleRef bundle = CFBundleGetMainBundle();

	if(bundle)
	{
		// get the url to the bundles root
		CFURLRef url = CFBundleCopyBundleURL(bundle);

		if(url)
		{
			// get the file system path
			CFStringRef str;
			str = CFURLCopyFileSystemPath(
				CFURLCopyAbsoluteURL(url), kCFURLPOSIXPathStyle);
			CFRelease(url);
	
			if(str)
			{
				cachedPathToBundle = CFStringGetCStringPtr(
					str, CFStringGetSmallestEncoding(str));
				CFRelease(str);
			}
			else
				nlerror("CFStringGetCStringPtr");
		}
		else
			nlerror("CFBundleCopyBundleURL");
	}
	else
		nlerror("CFBundleGetMainBundle");
#elif defined(NL_OS_WINDOWS)
	char buffer[MAX_PATH+1];
	if (GetModuleFileNameA(NULL, buffer, MAX_PATH))
		cachedPathToBundle = NLMISC::CPath::standardizePath(NLMISC::CFile::getPath(buffer), false);
#endif // defined(NL_OS_MAC)
	
	return cachedPathToBundle;
}
Ejemplo n.º 7
0
// ***************************************************************************
const NLMISC::CVector& CInstanceGroupUser::getInstanceScale (uint instanceNb) const
{
	// Check args
	if (instanceNb>=_InstanceGroup.getNumInstance ())
		nlerror("getInstanceScale*(): bad instance Id");

	return _InstanceGroup.getInstanceScale (instanceNb);
}
Ejemplo n.º 8
0
// ***************************************************************************
const NLMISC::CQuat& CInstanceGroupUser::getInstanceRot (uint instanceNb) const
{
	// Check args
	if (instanceNb>=_InstanceGroup.getNumInstance ())
		nlerror("getInstanceRot*(): bad instance Id");

	return _InstanceGroup.getInstanceRot (instanceNb);
}
Ejemplo n.º 9
0
// ***************************************************************************
const std::string& CInstanceGroupUser::getInstanceName (uint instanceNb) const
{
	// Check args
	if (instanceNb>=_InstanceGroup.getNumInstance ())
		nlerror("getInstanceName*(): bad instance Id");

	return _InstanceGroup.getInstanceName (instanceNb);
}
Ejemplo n.º 10
0
UBone		USkeleton::getBone(uint boneId) const
{
	NL3D_HAUTO_UI_SKELETON;
	CSkeletonModel	*object = getObjectPtr();

	if(boneId>=object->Bones.size())
		nlerror("getBone(): bad boneId");
	return UBone (&(object->Bones[boneId]));
}
Ejemplo n.º 11
0
void		USkeleton::stickObjectEx(UTransform mi, uint boneId, bool forceCLod)
{
	NL3D_HAUTO_UI_SKELETON;
	CSkeletonModel	*object = getObjectPtr();

	if(mi.empty())
		nlerror("USkeleton::stickObject(): mi is NULL");
	CTransform		*trans= dynamic_cast<CTransform*>(mi.getObjectPtr());
	object->stickObjectEx(trans, boneId, forceCLod);
}
Ejemplo n.º 12
0
void		USkeleton::detachSkeletonSon(UTransform mi)
{
	NL3D_HAUTO_UI_SKELETON;
	CSkeletonModel	*object = getObjectPtr();

	if(mi.empty())
		nlerror("USkeleton::detachSkeletonSon(): mi is NULL");
	CTransform		*trans= dynamic_cast<CTransform*>(mi.getObjectPtr());
	object->detachSkeletonSon(trans);
}
Ejemplo n.º 13
0
bool		USkeleton::bindSkin(UInstance mi)
{
	NL3D_HAUTO_UI_SKELETON;

	if(mi.empty())
	{
		nlerror("USkeleton::bindSkin(): mi is NULL");
		return false;
	}
	CTransform			*trans= dynamic_cast<CTransform*>(mi.getObjectPtr());
	CMeshBaseInstance	*meshi= dynamic_cast<CMeshBaseInstance*>(trans);
	if(meshi==NULL)
	{
		nlerror("USkeleton::bindSkin(): mi is not a MeshInstance or MeshMRMInstance");
		return false;
	}
	CSkeletonModel	*object = getObjectPtr();
	return object->bindSkin(meshi);
}
Ejemplo n.º 14
0
//----------------------------------------------------------------------------
void CModuleParent::addChildModule(IModule* module)
{
    MODULE_INFO( "Module parent : simply adding a child module" );
    MODULE_AST( module );
#ifdef RY_MODULE_DEBUG
    NLMISC::CRefPtr<IModule> ref(module);
    std::vector< NLMISC::CRefPtr<IModule> >::iterator it( std::find( _Modules.begin(), _Modules.end(), ref ) );
    if ( it != _Modules.end() )
        nlerror("a module was added twice");
#endif
    _Modules.push_back(module);
}
Ejemplo n.º 15
0
// method used to prolong a sabrina action (eg prolong cast...)
void CSabrinaPhraseInstance::addTimeBeforeNextEvent(uint32 ticks)
{
	if (!isActive())
	{
		#ifdef NL_DEBUG
			nlerror("CSabrinaPhraseInstance::addTimeBeforeNextEvent(): phrase instance is inactive");
		#endif
		return;
	}
	_NextEventTime+= ticks;
	CSabrinaPhraseManager::setNextPhraseEvent(this,_NextEventTime);
}
void CParticleEditor::saveWorkspaceStructure()
{
	nlassert(_PW);
	try
	{
		_PW->save();
	}
	catch(NLMISC::EStream &e)
	{
		nlerror(e.what());
	}
}
Ejemplo n.º 17
0
std::string CGroupController::getPath() // overridden by root
{
	for (std::map<std::string, CGroupController *>::iterator it(m_Parent->m_Children.begin()), end(m_Parent->m_Children.end()); it != end; ++it)
	{
		if (it->second == this)
		{
			const std::string &name = it->first;
			std::string returnPath = m_Parent->getPath() + ":" + name;
			return returnPath;
		}
	}
	nlerror("Group Controller not child of parent");
	return "";
}
void CParticleEditor::createNewWorkspace(const std::string &fullPath)
{
	CParticleWorkspace *newPW = new CParticleWorkspace;
	newPW->init(fullPath);
	// save empty workspace
	try
	{
		newPW->save();
	}
	catch(NLMISC::EStream &e)
	{
		nlerror(e.what());
	}
	closeWorkspace();
	_PW = newPW;
}
Ejemplo n.º 19
0
bool QNLWidget::macEvent(EventHandlerCallRef caller, EventRef event)
{
    if(caller)
        nlerror("You are using QtCarbon! Only QtCocoa supported, please upgrade Qt");

    if (m_driver && m_driver->isActive())
    {
        NL3D::IDriver *driver = dynamic_cast<NL3D::CDriverUser *>(m_driver)->getDriver();
        if (driver)
        {
            cocoaProc proc = (cocoaProc)driver->getWindowProc();
            return proc(driver, event);
        }
    }

    return false;
}
Ejemplo n.º 20
0
// ***************************************************************************
void CListenerFMod::setRolloffFactor( float f )
{
	// Works only in API rolloff mode
	if (CSoundDriverFMod::getInstance()->getOption(ISoundDriver::OptionManualRolloff))
		nlerror("OptionManualRolloff");
	else
	{
		if(!CSoundDriverFMod::getInstance()->fmodOk())
			return;

		// clamp as in DSound (FMod requirement)
		clamp(f, 0.f, 10.f);

		_RolloffFactor = f;

		// set
		FSOUND_3D_SetRolloffFactor(f);
	}
}
void CParticleEditor::loadWorkspace(const std::string &fullPath)
{
	// Add to the path
	std::auto_ptr<CParticleWorkspace> newPW(new CParticleWorkspace);
	newPW->init(fullPath);
	
	// save empty workspace
	try
	{
		newPW->load();
	}
	catch(NLMISC::EStream &e)
	{
		nlerror(e.what());
		return;
	}	
	
	// try to load each ps
	CWorkspaceNode *firstLoadedNode = NULL;
	TPWNodeItr itr = newPW->getNodeList().begin();
	while(itr != newPW->getNodeList().end())
	{
		CWorkspaceNode *node = (*itr);
		try
		{
			node->loadPS();
		}
		catch(NLMISC::EStream &e)
		{
			nlwarning(e.what());
		}
		if (node->isLoaded() && !firstLoadedNode)
			firstLoadedNode = node;
		itr++;
	}
	closeWorkspace();
	_PW = newPW.release();
	setActiveNode(firstLoadedNode);
}
Ejemplo n.º 22
0
// ***************************************************************************
void			UTransform::parent(UTransform newFather)
{
	CTransform	*object = getObjectPtr();
	if (object->getForceClipRoot())
	{
		nlwarning("Transform has been flagged to be glued to the root, can't change parent. See UTransform::setForceClipRoot(bool).");
		return;
	}
	if(!newFather.empty())
	{
		// link me to other.
		CTransform	*other= newFather.getObjectPtr();
		if(other->getOwnerScene()!=object->getOwnerScene())
			nlerror("Try to parent 2 object from 2 differnet scenes!!");
		other->hrcLinkSon( object );
	}
	else
	{
		// link me to Root.
		object->getOwnerScene()->getRoot()->hrcLinkSon( object );
	}
}
Ejemplo n.º 23
0
// method used to prematurely abort execution of phrase
void CSabrinaPhraseInstance::abortPhrase(SABRINA::TEventCode reason)
{
	switch (_State)
	{
	case Inactive:
		return;

	case PostActionDelay:
		return;

	case PreActionDelay:
		// call the actor's phrase cancelation callback
		_Actor->cbSabrinaActionCancel(this,reason);
		// terminate the phrase
		terminate();
		return;

	default:
		#ifdef NL_DEBUG
			nlerror("CSabrinaPhraseInstance::abortPhrase(): Bad '_State' value: %d",(uint32)_State);
		#endif
	}
}
void CSheetId::loadSheetId ()
{
	H_AUTO(CSheetIdInit);
	//nldebug("Loading sheet_id.bin");

	// Open the sheet id to sheet file name association
	CIFile file;
	std::string path = CPath::lookup("sheet_id.bin", false, false);
	if(!path.empty() && file.open(path))
	{
		// clear entries
		_FileExtensions.clear ();
		_SheetIdToName.clear ();
		_SheetNameToId.clear ();

		// reserve space for the vector of file extensions
		_FileExtensions.resize(1 << (NL_SHEET_ID_TYPE_BITS));

		// Get the map from the file
		map<uint32,string> tempMap;
		contReset(tempMap);
		file.serialCont(tempMap);
		file.close();

		if (_RemoveUnknownSheet)
		{
			uint32 removednbfiles = 0;
			uint32 nbfiles = (uint32)tempMap.size();

			// now we remove all files that not available
			map<uint32,string>::iterator itStr2;
			for( itStr2 = tempMap.begin(); itStr2 != tempMap.end(); )
			{
				if (CPath::exists ((*itStr2).second))
				{
					++itStr2;
				}
				else
				{
					map<uint32,string>::iterator olditStr = itStr2;
					//nldebug ("Removing file '%s' from CSheetId because the file not exists", (*olditStr).second.c_str ());
					itStr2++;
					tempMap.erase (olditStr);
					removednbfiles++;
				}
			}
			nlinfo ("SHEETID: Removed %d files on %d from CSheetId because these files doesn't exists", removednbfiles, nbfiles);
		}

		// Convert the map to one big string and 1 static map (id to name)
		{
			// Get the number and size of all strings
			vector<CChar> tempVec; // Used to initialise the first map
			uint32 nNb = 0;
			uint32 nSize = 0;
			map<uint32,string>::const_iterator it = tempMap.begin();
			while (it != tempMap.end())
			{
				nSize += (uint32)it->second.size()+1;
				nNb++;
				it++;
			}

			// Make the big string (composed of all strings) and a vector referencing each string
			tempVec.resize(nNb);
			_AllStrings.Ptr = new char[nSize];
			it = tempMap.begin();
			nSize = 0;
			nNb = 0;
			while (it != tempMap.end())
			{
				tempVec[nNb].Ptr = _AllStrings.Ptr+nSize;
				strcpy(_AllStrings.Ptr+nSize, it->second.c_str());
				toLower(_AllStrings.Ptr+nSize);
				nSize += (uint32)it->second.size()+1;
				nNb++;
				it++;
			}

			// Finally build the static map (id to name)
			_SheetIdToName.reserve(tempVec.size());
			it = tempMap.begin();
			nNb = 0;
			while (it != tempMap.end())
			{
				_SheetIdToName.add(pair<uint32, CChar>(it->first, CChar(tempVec[nNb])));

				nNb++;
				it++;
			}

			// The vector of all small string is not needed anymore we have all the info in
			// the static map and with the pointer AllStrings referencing the beginning.
		}

		// Build the invert map (Name to Id) & file extension vector
		{
			uint32 nSize = (uint32)_SheetIdToName.size();
			_SheetNameToId.reserve(nSize);
			CStaticMap<uint32,CChar>::iterator itStr;
			for( itStr = _SheetIdToName.begin(); itStr != _SheetIdToName.end(); ++itStr )
			{
				// add entry to the inverse map
				_SheetNameToId.add( make_pair((*itStr).second, (*itStr).first) );

				// work out the type value for this entry in the map
				TSheetId sheetId;
				sheetId.Id=(*itStr).first;
				uint32 type = sheetId.IdInfos.Type;

				// check whether we need to add an entry to the file extensions vector
				if (_FileExtensions[type].empty())
				{
					// find the file extension part of the given file name
					_FileExtensions[type] = toLower(CFile::getExtension((*itStr).second.Ptr));
				}
				nSize--;
			}
			_SheetNameToId.endAdd();
		}
	}
	else
	{
		nlerror("<CSheetId::init> Can't open the file sheet_id.bin");
	}
	nldebug("Finished loading sheet_id.bin: %u entries read",_SheetIdToName.size());
}
Ejemplo n.º 25
0
/*------------------------------------------------------------------*\
							emulateMouseRawMode()
\*------------------------------------------------------------------*/
void CWinEventEmitter::emulateMouseRawMode(bool enable)
{
	nlerror("no raw mode emulation on windows, the CDIMouse has a real raw mode");
}
Ejemplo n.º 26
0
	void CObjectViewer::setCurrentObject(const std::string &name)
	{
		if ((_Entities.count(name) != 0) || ( name.empty() )) _CurrentInstance = name;
		else nlerror ("Entity %s not found", name.c_str());
		nlinfo("set current entity %s", _CurrentInstance.c_str());
	}
Ejemplo n.º 27
0
	CEntity& CObjectViewer::getEntity(const std::string &name)
	{
		if ( _Entities.count(name) == 0) nlerror("Entity %s not found", name.c_str());
		EIT eit = _Entities.find (name);
		return (*eit).second;
	}