⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 agents.cpp

📁 一个由Mike Gashler完成的机器学习方面的includes neural net, naive bayesian classifier, decision tree, KNN, a genet
💻 CPP
字号:
// --------------------------------------------------------
// This demo file is dedicated to the Public Domain. See:
// http://creativecommons.org/licenses/publicdomain
// --------------------------------------------------------

#include "Agents.h"
#ifdef WIN32
#else // WIN32
#include <unistd.h>
#endif // !WIN32
#include "../GClasses/GTime.h"
#include "../GClasses/GThread.h"
#include "../GClasses/GMacros.h"
#include "../GClasses/GFile.h"





// -----------------------------------------------------------------


class AgentsMenuDialog : public GWidgetDialog
{
protected:
	AgentsMenuController* m_pController;
	GWidgetImageButton* m_pButtonManual;
	GWidgetTextButton* m_pButtonCarOnHill;

public:
	AgentsMenuDialog(AgentsMenuController* pController, int w, int h);
	virtual ~AgentsMenuDialog();

	virtual void OnChangeListSelection(GWidgetListBox* pListBox);
	virtual void OnReleaseTextButton(GWidgetTextButton* pButton);

	virtual void OnReleaseImageButton(GWidgetImageButton* pButton)
	{
		if(pButton == m_pButtonManual)
			OpenAppFile("../doc/Waffles/Agents.html");
		else
			GAssert(false, "unrecognized image button");
	}
};



// -----------------------------------------------------------------


#define BACKGROUND_COLOR 0xff220044

AgentsMenuDialog::AgentsMenuDialog(AgentsMenuController* pController, int w, int h)
 : GWidgetDialog(w, h, BACKGROUND_COLOR)
{
	m_pController = pController;

	// Make the manual button
	GImage* pManualImage = ControllerBase::GetManualImage();
	m_pButtonManual = new GWidgetImageButton(this, w - pManualImage->GetWidth() / 2 - 5, 5, pManualImage);

	m_pButtonCarOnHill = new GWidgetTextButton(this, 25, 100, 200, 24, "Car on hill");
}

/*virtual*/ AgentsMenuDialog::~AgentsMenuDialog()
{
}

/*virtual*/ void AgentsMenuDialog::OnChangeListSelection(GWidgetListBox* pListBox)
{
}

/*virtual*/ void AgentsMenuDialog::OnReleaseTextButton(GWidgetTextButton* pButton)
{
	if(pButton == m_pButtonCarOnHill)
	{
		//SomeController c;
		//c.RunModal();
	}
	else
		GAssert(false, "unrecognized button");
}




// -------------------------------------------------------------------------------

class AgentsMenuView : public ViewBase
{
protected:
	AgentsMenuDialog* m_pDialog;

public:
	AgentsMenuView(AgentsMenuController* pController);
	virtual ~AgentsMenuView();

	virtual void OnChar(char c);
	virtual void OnMouseDown(int nButton, int x, int y);
	virtual void OnMouseUp(int nButton, int x, int y);
	virtual bool OnMousePos(int x, int y);

protected:
	virtual void Draw(SDL_Surface *pScreen);
};

AgentsMenuView::AgentsMenuView(AgentsMenuController* pController)
: ViewBase()
{
	m_pDialog = new AgentsMenuDialog(pController, m_screenRect.w, m_screenRect.h);
}

AgentsMenuView::~AgentsMenuView()
{
	delete(m_pDialog);
}

/*virtual*/ void AgentsMenuView::Draw(SDL_Surface *pScreen)
{
	// Clear the screen
	SDL_FillRect(pScreen, NULL/*&r*/, 0x000000);

	// Draw the dialog
	BlitImage(pScreen, m_screenRect.x, m_screenRect.y, m_pDialog->GetImage());
}

void AgentsMenuView::OnChar(char c)
{
	m_pDialog->HandleChar(c);
}

void AgentsMenuView::OnMouseDown(int nButton, int x, int y)
{
	x -= m_screenRect.x;
	y -= m_screenRect.y;
	GWidgetAtomic* pNewWidget = m_pDialog->FindAtomicWidget(x, y);
	m_pDialog->GrabWidget(pNewWidget, nButton, x, y);
}

void AgentsMenuView::OnMouseUp(int nButton, int x, int y)
{
	m_pDialog->ReleaseWidget(nButton);
}

bool AgentsMenuView::OnMousePos(int x, int y)
{
	return m_pDialog->HandleMousePos(x - m_screenRect.x, y - m_screenRect.y);
}



// -------------------------------------------------------------------------------




AgentsMenuController::AgentsMenuController()
: ControllerBase()
{
	m_pView = new AgentsMenuView(this);
}

AgentsMenuController::~AgentsMenuController()
{
	delete(m_pView);
}

void AgentsMenuController::RunModal()
{
	double timeOld = GTime::GetTime();
	double time;
	m_pView->Update();
	while(m_bKeepRunning)
	{
		time = GTime::GetTime();
		if(HandleEvents(time - timeOld)) // HandleEvents returns true if it thinks the view needs to be updated
		{
			m_pView->Update();
		}
		else
			GThread::sleep(10);
		timeOld = time;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -