예제 #1
0
//---------------------------------------------------------------------------------------------------------------------
// EventManager::VQueueEvent
//---------------------------------------------------------------------------------------------------------------------
bool EventManager::VQueueEvent(const IEventDataPtr& pEvent)
{
	GCC_ASSERT(m_activeQueue >= 0);
	GCC_ASSERT(m_activeQueue < EVENTMANAGER_NUM_QUEUES);

    // make sure the event is valid
    if (!pEvent)
    {
        GCC_ERROR("Invalid event in VQueueEvent()");
        return false;
    }

    GCC_LOG("Events", "Attempting to queue event: " + std::string(pEvent->GetName()));

	auto findIt = m_eventListeners.find(pEvent->VGetEventType());
    if (findIt != m_eventListeners.end())
    {
        m_queues[m_activeQueue].push_back(pEvent);
        GCC_LOG("Events", "Successfully queued event: " + std::string(pEvent->GetName()));
        return true;
    }
    else
    {
        GCC_LOG("Events", "Skipping event since there are no delegates registered to receive it: " + std::string(pEvent->GetName()));
        return false;
    }
}
예제 #2
0
//---------------------------------------------------------------------------------------------------------------------
// EventManager::VAbortEvent
//---------------------------------------------------------------------------------------------------------------------
bool EventManager::VAbortEvent(const EventType& inType, bool allOfType)
{
	GCC_ASSERT(m_activeQueue >= 0);
	GCC_ASSERT(m_activeQueue < EVENTMANAGER_NUM_QUEUES);

    bool success = false;
	EventListenerMap::iterator findIt = m_eventListeners.find(inType);

	if (findIt != m_eventListeners.end())
    {
        EventQueue& eventQueue = m_queues[m_activeQueue];
        auto it = eventQueue.begin();
        while (it != eventQueue.end())
        {
            // Removing an item from the queue will invalidate the iterator, so have it point to the next member.  All
            // work inside this loop will be done using thisIt.
            auto thisIt = it;
            ++it;

	        if ((*thisIt)->VGetEventType() == inType)
	        {
		        eventQueue.erase(thisIt);
		        success = true;
		        if (!allOfType)
			        break;
	        }
        }
    }

	return success;
}
예제 #3
0
float PathingNode::GetCostFromNode(PathingNode* pFromNode)
{
	GCC_ASSERT(pFromNode);
	PathingArc* pArc = FindArc(pFromNode);
	GCC_ASSERT(pArc);
	Vec3 diff = pFromNode->GetPos() - m_pos;
	return pArc->GetWeight() * diff.Length();
}
예제 #4
0
//--------------------------------------------------------------------------------------------------------
// PathingArc
//--------------------------------------------------------------------------------------------------------
void PathingArc::LinkNodes(PathingNode* pNodeA, PathingNode* pNodeB)
{
	GCC_ASSERT(pNodeA);
	GCC_ASSERT(pNodeB);

	m_pNodes[0] = pNodeA;
	m_pNodes[1] = pNodeB;
}
예제 #5
0
//---------------------------------------------------------------------------------------------------------------------
// Removes a script listener.
//---------------------------------------------------------------------------------------------------------------------
void InternalScriptExports::RemoveEventListener(unsigned long listenerId)
{
	GCC_ASSERT(s_pScriptEventListenerMgr);
	GCC_ASSERT(listenerId != 0);
	
	// convert the listenerId back into a pointer
	ScriptEventListener* pListener = reinterpret_cast<ScriptEventListener*>(listenerId);
	s_pScriptEventListenerMgr->DestroyListener(pListener);  // the destructor will remove the listener
}
예제 #6
0
void PathingGraph::LinkNodes(PathingNode* pNodeA, PathingNode* pNodeB)
{
	GCC_ASSERT(pNodeA);
	GCC_ASSERT(pNodeB);
	
	PathingArc* pArc = GCC_NEW PathingArc;
	pArc->LinkNodes(pNodeA,pNodeB);
	pNodeA->AddArc(pArc);
	pNodeB->AddArc(pArc);
	m_arcs.push_back(pArc);
}
예제 #7
0
//---------------------------------------------------------------------------------------------------------------------
// This function is called to register an event type with the script to link them.  The simplest way to do this is 
// with the REGISTER_SCRIPT_EVENT() macro, which calls this function.
//---------------------------------------------------------------------------------------------------------------------
void ScriptEvent::RegisterEventTypeWithScript(const char* key, EventType type)
{
	// get or create the EventType table
	LuaPlus::LuaObject eventTypeTable = LuaStateManager::Get()->GetGlobalVars().GetByName("EventType");
	if (eventTypeTable.IsNil())
		eventTypeTable = LuaStateManager::Get()->GetGlobalVars().CreateTable("EventType");

	// error checking
	GCC_ASSERT(eventTypeTable.IsTable());
	GCC_ASSERT(eventTypeTable[key].IsNil());
	
	// add the entry
	eventTypeTable.SetNumber(key, (double)type);
}
예제 #8
0
void BaseScriptComponent::CreateScriptObject(void)
{
    LuaStateManager* pStateMgr = LuaStateManager::Get();
    GCC_ASSERT(pStateMgr);
	GCC_ASSERT(!m_scriptObject.IsNil());
	
	LuaPlus::LuaObject metaTableObj = pStateMgr->GetGlobalVars().Lookup(METATABLE_NAME);
	GCC_ASSERT(!metaTableObj.IsNil());
	
	LuaPlus::LuaObject boxedPtr = pStateMgr->GetLuaState()->BoxPointer(this);
	boxedPtr.SetMetaTable(metaTableObj);
	m_scriptObject.SetLightUserData("__object", this);
	m_scriptObject.SetMetaTable(metaTableObj);
}
예제 #9
0
	void* MemoryUsageObject::operator new[](size_t size) {
		//cout << "MemoryUsageObject::new[]" << endl;
		GCC_ASSERT(s_pMemoryPool);
		void* pMem = s_pMemoryPool->Alloc();
		//cout << "End MemoryUsageObject::new[]" << endl;
		return pMem;
	}
예제 #10
0
파일: Network.cpp 프로젝트: snikk/Junk
void NetSocket::VHandleOutput() {
    int fSent = 0;
    do {
        GCC_ASSERT(!m_OutList.empty());
        PacketList::iterator i = m_OutList.begin();

        std::shared_ptr<IPacket> pkt = *i;
        const char* buf = pkt->VGetData();
        int len = static_cast<int>(pkt->VGetSize());

        int rc = send(m_sock, buf + m_sendOfs, len - m_sendOfs, 0);
        if (rc > 0) {
            g_pSocketManager->AddToOutbound(rc);
            m_sendOfs += rc;
            fSent = 1;
        } else if (WSAGetLastError() != WSAEWOULDBLOCK) {
            HandleException();
            fSent = 0;
        } else {
            fSent = 0;
        }

        if (m_sendOfs == pkt->VGetSize()) {
            m_OutList.pop_front();
            m_sendOfs = 0;
        }

    } while (fSent && !m_OutList.empty());
}
예제 #11
0
//
// HumanView::HumanView - Chapter 10, page 272
//
HumanView::HumanView(shared_ptr<IRenderer> renderer)
{
	InitAudio(); 

	m_pProcessManager = GCC_NEW ProcessManager;

	m_PointerRadius = 1;	// we assume we are on a mouse enabled machine - if this were a tablet we should detect it here.
	m_ViewId = gc_InvalidGameViewId;

	// Added post press for move, new, and destroy actor events and others
	RegisterAllDelegates();
	m_BaseGameState = BGS_Initializing;		// what is the current game state

	if (renderer)
	{
		// Moved to the HumanView class post press
		m_pScene.reset(GCC_NEW ScreenElementScene(renderer));

		Frustum frustum;
		frustum.Init(GCC_PI/4.0f, 1.0f, 1.0f, 100.0f);
		m_pCamera.reset(GCC_NEW CameraNode(&Mat4x4::g_Identity, frustum));
		GCC_ASSERT(m_pScene && m_pCamera && _T("Out of memory"));

		m_pScene->VAddChild(INVALID_ACTOR_ID, m_pCamera);
		m_pScene->SetCamera(m_pCamera);
	}
}
예제 #12
0
// 
// BitmapSprite::VOnRestore - Chapter 10, page 322
//
HRESULT BitmapSprite::VOnRestore()
{
	if (FAILED (Sprite::VOnRestore() ) )
	{
		return E_FAIL;
	}

	SAFE_RELEASE(m_pTexture);

    D3DXIMAGE_INFO imageInfo;
	ZeroMemory(&imageInfo, sizeof(D3DXIMAGE_INFO));

	if (m_bInCache)
	{
		Resource resource(m_fileName.c_str());
		shared_ptr<ResHandle> texture = g_pApp->m_ResCache->GetHandle(&resource);
		if ( FAILED ( D3DXCreateTextureFromFileInMemoryEx( 
			DXUTGetD3D9Device(), // device
			texture->Buffer(),		// source data
			texture->Size(),	// source data size
			D3DX_DEFAULT,		// width - get it from the file
			D3DX_DEFAULT,		// height - get it from the file
			D3DX_DEFAULT,		// miplevels - get it from the file
			0,					// useage - default (not a render target or dynamic)
			D3DFMT_UNKNOWN,		// format - get it from the file
			D3DPOOL_DEFAULT,	// pool - use default
			D3DX_FILTER_NONE,	// filter - don't use any filter
			D3DX_DEFAULT,		// mip filter - use default
			g_Transparent,		// color key - use our transparent color
			&imageInfo,			// grab the source info
			NULL,				// palleteindex - we don't need it
			&m_pTexture ) ) )	// the texture pointer
			return false;
	}
	else
	{
		if ( FAILED ( D3DXCreateTextureFromFileExA ( 
			DXUTGetD3D9Device(), 
			m_fileName.c_str(),	// source file name
			D3DX_DEFAULT,		// width - get it from the file
			D3DX_DEFAULT,		// height - get it from the file
			D3DX_DEFAULT,		// miplevels - get it from the file
			0,					// useage - default (not a render target or dynamic)
			D3DFMT_UNKNOWN,		// format - get it from the file
			D3DPOOL_DEFAULT,	// pool - use default
			D3DX_FILTER_NONE,	// filter - don't use any filter
			D3DX_DEFAULT,		// mip filter - use default
			g_Transparent,		// color key - use our transparent color
			&imageInfo,			// grab the source info
			NULL,				// palleteindex - we don't need it
			&m_pTexture ) ) )	// the texture pointer
			return false;
	}

	m_TextureWidth = m_Width = imageInfo.Width;
	m_TextureHeight = m_Height = imageInfo.Height / m_NumFrames;
	GCC_ASSERT(m_Height * m_NumFrames == imageInfo.Height && _T("Sprite height error"));

	return true;
}
예제 #13
0
//
// AStar::InsertNode					- Chapter 17, page 636
//
void AStar::InsertNode(PathPlanNode* pNode)
{
	GCC_ASSERT(pNode);
	
	// just add the node if the open set is empty
	if (m_openSet.empty())
	{
		m_openSet.push_back(pNode);
		return;
	}

	// otherwise, perform an insertion sort	
	PathPlanNodeList::iterator it = m_openSet.begin();
	PathPlanNode* pCompare = *it;
	while (pCompare->IsBetterChoiceThan(pNode))
	{
		++it;
		
		if (it != m_openSet.end())
			pCompare = *it;
		else
			break;
	}
	m_openSet.insert(it,pNode);
}
예제 #14
0
//---------------------------------------------------------------------------------------------------------------------
// Initializes the script export system
//---------------------------------------------------------------------------------------------------------------------
bool InternalScriptExports::Init(void)
{
	GCC_ASSERT(s_pScriptEventListenerMgr == NULL);
	s_pScriptEventListenerMgr = GCC_NEW ScriptEventListenerMgr;
	
	return true;
}
예제 #15
0
void ScriptEventListener::ScriptEventDelegate(IEventDataPtr pEvent)
{
    GCC_ASSERT(m_scriptCallbackFunction.IsFunction());  // this should never happen since it's validated before even creating this object

    // call the Lua function
	shared_ptr<ScriptEvent> pScriptEvent = static_pointer_cast<ScriptEvent>(pEvent);
	LuaPlus::LuaFunction<void> Callback = m_scriptCallbackFunction;
	Callback(pScriptEvent->GetEventData());
}
예제 #16
0
PathingNode* PathingArc::GetNeighbor(PathingNode* pMe)
{
	GCC_ASSERT(pMe);
	
	if (m_pNodes[0] == pMe)
		return m_pNodes[1];
	else
		return m_pNodes[0];
}
예제 #17
0
//--------------------------------------------------------------------------------------------------------
// PathPlanNode
//--------------------------------------------------------------------------------------------------------
PathPlanNode::PathPlanNode(PathingNode* pNode, PathPlanNode* pPrevNode, PathingNode* pGoalNode)
{
	GCC_ASSERT(pNode);
	
	m_pPathingNode = pNode;
	m_pPrev = pPrevNode;  // NULL is a valid value, though it should only be NULL for the start node
	m_pGoalNode = pGoalNode;
	m_closed = false;
	UpdateHeuristics();
}
예제 #18
0
//
// TeapotController::VOnLButtonDown				- Chapter 19, page 735
//
bool TeapotController::VOnPointerButtonDown(const Point &mousePos, const int radius, const std::string &buttonName)
{
	if (buttonName != "PointerLeft")
		return false;
	ActorId actorId = m_object->VGet()->ActorId();
	GCC_ASSERT(actorId != INVALID_ACTOR_ID && _T("The teapot controller isn't attached to a valid actor!"));
    shared_ptr<EvtData_Fire_Weapon> pFireEvent(GCC_NEW EvtData_Fire_Weapon(actorId));
    IEventManager::Get()->VQueueEvent(pFireEvent);
	return true;
}
예제 #19
0
파일: Sky.cpp 프로젝트: AsbjoernS/gamecode4
std::string SkyNode::GetTextureName(const int side)
{
	std::string name = m_textureBaseName;
	char *letters[] = { "n", "e", "s", "w", "u" };
	unsigned int index = name.find_first_of("_");
	GCC_ASSERT(index >= 0 && index < name.length()-1);
	if (index >= 0 && index < name.length()-1)
	{
		name[index+1] = *letters[side];
	}
	return name;
}
예제 #20
0
PathingArc* PathingNode::FindArc(PathingNode* pLinkedNode)
{
	GCC_ASSERT(pLinkedNode);
	
	for (PathingArcList::iterator it = m_arcs.begin(); it != m_arcs.end(); ++it)
	{
		PathingArc* pArc = *it;
		if (pArc->GetNeighbor(this) == pLinkedNode)
			return pArc;
	}
	return NULL;
}
예제 #21
0
	void MemoryUsageObject::destroyMemoryPool(void) {
		cout << "MemoryUsageObject::destroyMemoryPool" << endl;


		GCC_ASSERT(s_pMemoryPool);

		//GCC_ASSERT(!s_pMemoryPool);
		//GCC_ASSERT(s_pMemoryPool != nullptr);
		//templates::safe_delete<MemoryPool>(s_pMemoryPool);
		memory_pool::safe_delete(s_pMemoryPool);
		cout << "End MemoryUsageObject::destroyMemoryPool" << endl;
	}
예제 #22
0
//
// ResCache::GetHandle							- Chapter 8, page 227
//
shared_ptr<ResHandle> ResCache::GetHandle(Resource * r)
{
	shared_ptr<ResHandle> handle(Find(r));
	if (handle==NULL)
	{
		handle = Load(r);
		GCC_ASSERT(handle);
	}
	else
	{
		Update(handle);
	}
	return handle;
}
예제 #23
0
//
// SdkMeshResourceLoader::VLoadResource						- Chapter 16, page 561
//
bool SdkMeshResourceLoader::VLoadResource(char *rawBuffer, unsigned int rawSize, shared_ptr<ResHandle> handle)
{
	GameCodeApp::Renderer renderer = GameCodeApp::GetRendererImpl();
	if (renderer == GameCodeApp::Renderer_D3D9)
	{
		GCC_ASSERT(0 && "This is not supported in D3D9");
	}
	else if (renderer == GameCodeApp::Renderer_D3D11)
	{
		shared_ptr<D3DSdkMeshResourceExtraData11> extra = shared_ptr<D3DSdkMeshResourceExtraData11>(GCC_NEW D3DSdkMeshResourceExtraData11());

		// Load the Mesh
	    if (SUCCEEDED ( extra->m_Mesh11.Create( DXUTGetD3D11Device(), (BYTE *)rawBuffer, (UINT)rawSize, true ) ) )
		{
			handle->SetExtra(shared_ptr<D3DSdkMeshResourceExtraData11>(extra));
		}

		return true;
	}

	GCC_ASSERT(0 && "Unsupported Renderer in SdkMeshResourceLoader::VLoadResource");
	return false;
}
예제 #24
0
PathPlan* AStar::RebuildPath(PathPlanNode* pGoalNode)
{
	GCC_ASSERT(pGoalNode);

	PathPlan* pPlan = GCC_NEW PathPlan;

	PathPlanNode* pNode = pGoalNode;
	while (pNode)
	{
		pPlan->AddNode(pNode->GetPathingNode());
		pNode = pNode->GetPrev();
	}
	
	return pPlan;
}
예제 #25
0
void AStar::ReinsertNode(PathPlanNode* pNode)
{
	GCC_ASSERT(pNode);

	for (PathPlanNodeList::iterator it = m_openSet.begin(); it != m_openSet.end(); ++it)
	{
		if (pNode == (*it))
		{
			m_openSet.erase(it);
			InsertNode(pNode);
			return;
		}
	}

	// if we get here, the node was never in the open set to begin with
    GCC_WARNING("Attemping to reinsert node that was never in the open list");
	InsertNode(pNode);
}
예제 #26
0
파일: templates.hpp 프로젝트: Ostkaka/ANT
    optional & operator = (optional const & other)
    {
		GCC_ASSERT(! (this == & other));	// don't copy over self!
		if (m_bValid)
		{						// first, have to destroy our original.
			m_bValid = false;	// for exception safety if destroy() throws.
								// (big trouble if destroy() throws, though)
			destroy();
		}

		if (other.m_bValid)
		{
			construct(* other);
			m_bValid = true;	// order vital.

		}
		return * this;
    }
예제 #27
0
//---------------------------------------------------------------------------------------------------------------------
// Instantiates a C++ ScriptListener object, inserts it into the manager, and returns a handle to it.  The script 
// should maintain the handle if it needs to remove the listener at some point.  Otherwise, the listener will be 
// destroyed when the program exits.
//---------------------------------------------------------------------------------------------------------------------
unsigned long InternalScriptExports::RegisterEventListener(EventType eventType, LuaPlus::LuaObject callbackFunction)
{
	GCC_ASSERT(s_pScriptEventListenerMgr);

	if (callbackFunction.IsFunction())
	{
		// create the C++ listener proxy and set it to listen for the event
		ScriptEventListener* pListener = GCC_NEW ScriptEventListener(eventType, callbackFunction);
		s_pScriptEventListenerMgr->AddListener(pListener);
		IEventManager::Get()->VAddListener(pListener->GetDelegate(), eventType);
		
		// convert the pointer to an unsigned long to use as the handle
		unsigned long handle = reinterpret_cast<unsigned long>(pListener);
		return handle;
	}

	GCC_ERROR("Attempting to register script event listener with invalid callback function");
	return 0;
}
예제 #28
0
//
// VorbisSeek									- Chapter 13, page 404
//
int VorbisSeek(void* data_src, ogg_int64_t offset, int origin)            
{
	OggMemoryFile *pVorbisData = static_cast<OggMemoryFile *>(data_src);
	if (NULL == pVorbisData) 
	{
		return -1;
	}

	switch (origin)
	{
		case SEEK_SET: 
		{ 
		  ogg_int64_t actualOffset; 
		  actualOffset = (pVorbisData->dataSize >= offset) ? offset : pVorbisData->dataSize;
		  pVorbisData->dataRead = static_cast<size_t>(actualOffset);
		  break;
		}

		case SEEK_CUR: 
		{
		  size_t spaceToEOF = 
			 pVorbisData->dataSize - pVorbisData->dataRead;

		  ogg_int64_t actualOffset; 
		  actualOffset = (offset < spaceToEOF) ? offset : spaceToEOF;  

		  pVorbisData->dataRead += static_cast<LONG>(actualOffset);
		  break;
		}

    case SEEK_END: 
		pVorbisData->dataRead = pVorbisData->dataSize+1;
		break;

    default:
      GCC_ASSERT(false && "Bad parameter for 'origin', requires same as fseek.");
      break;
  };

  return 0;
}
예제 #29
0
int MessageBox::Ask(MessageBox_Questions question)
{
	std::wstring msg;
	std::wstring title;
	int buttonFlags;
	int defaultAnswer = IDOK;

	switch(question)
	{
		case QUESTION_WHERES_THE_CD:
		{
			msg = g_pApp->GetString(_T("IDS_QUESTION_WHERES_THE_CD"));
			title = g_pApp->GetString(_T("IDS_ALERT"));
			buttonFlags = MB_RETRYCANCEL|MB_ICONEXCLAMATION;
			defaultAnswer = IDCANCEL;
			break;
		}
		case QUESTION_QUIT_GAME:
		{
			msg = g_pApp->GetString(_T("IDS_QUESTION_QUIT_GAME"));
			title = g_pApp->GetString(_T("IDS_QUESTION"));
			buttonFlags = MB_YESNO|MB_ICONQUESTION;
			defaultAnswer = IDNO;
			break;
		}
		default:
			GCC_ASSERT(0 && _T("Undefined question in Game::Ask"));
			return IDCANCEL;
	}

	if (g_pApp && g_pApp->IsRunning())
	{
		ShowCursor(true);
		shared_ptr<MessageBox> pMessageBox(new MessageBox(msg, title, buttonFlags));
		int result = g_pApp->Modal(pMessageBox, defaultAnswer);
		ShowCursor(false);
		return result;
	}

	return ::MessageBox(g_pApp ? g_pApp->GetHwnd() : NULL, msg.c_str(), title.c_str(), buttonFlags);
}
예제 #30
0
void PhysicsComponent::BuildRigidBodyTransform(TiXmlElement* pTransformElement)
{
	// FUTURE WORK Mrmike - this should be exactly the same as the TransformComponent - maybe factor into a helper method?
    GCC_ASSERT(pTransformElement);

    TiXmlElement* pPositionElement = pTransformElement->FirstChildElement("Position");
    if (pPositionElement)
    {
        double x = 0;
        double y = 0;
        double z = 0;
        pPositionElement->Attribute("x", &x);
        pPositionElement->Attribute("y", &y);
        pPositionElement->Attribute("z", &z);
        m_RigidBodyLocation = Vec3(x, y, z);
    }

    TiXmlElement* pOrientationElement = pTransformElement->FirstChildElement("Orientation");
    if (pOrientationElement)
    {
        double yaw = 0;
        double pitch = 0;
        double roll = 0;
        pPositionElement->Attribute("yaw", &yaw);
        pPositionElement->Attribute("pitch", &pitch);
        pPositionElement->Attribute("roll", &roll);
        m_RigidBodyOrientation = Vec3((float)DEGREES_TO_RADIANS(yaw), (float)DEGREES_TO_RADIANS(pitch), (float)DEGREES_TO_RADIANS(roll));
    }

    TiXmlElement* pScaleElement = pTransformElement->FirstChildElement("Scale");
    if (pScaleElement)
    {
        double x = 0;
        double y = 0;
        double z = 0;
        pScaleElement->Attribute("x", &x);
        pScaleElement->Attribute("y", &y);
        pScaleElement->Attribute("z", &z);
        m_RigidBodyScale = Vec3((float)x, (float)y, (float)z);
    }
}