Exemplo n.º 1
0
int main(int argc, char** argv)
{
	SoundTest app;

	// Read config file name from command line or use default one.
	const char* cfgName = "soundTest.cfg";
	if(argc == 2) cfgName = argv[1];

	Config* cfg = new Config(cfgName);

	DataManager* dm = DataManager::getInstance();
	// Add a default filesystem data source using current work dir.
	dm->addSource(new FilesystemDataSource("./"));
	dm->addSource(new FilesystemDataSource(OMICRON_DATA_PATH));

	ServiceManager* sm = new ServiceManager();
	sm->setupAndStart(cfg);

	float delay = -0.01f; // Seconds to delay sending events (<= 0 disables delay)
#ifdef _DEBUG
	bool printOutput = true;
#else
	bool printOutput = false;
#endif

	while(true)
	{
		sm->poll();

		// Get events
		int av = sm->getAvailableEvents();
		if(av != 0)
		{
			// TODO: Instead of copying the event list, we can lock the main one.
			Event evts[OMICRON_MAX_EVENTS];
			sm->getEvents(evts, OMICRON_MAX_EVENTS);
			for( int evtNum = 0; evtNum < av; evtNum++)
			{
				app.handleEvent(evts[evtNum]);
			}
			app.update();
			//if( printOutput )
			//	printf("------------------------------------------------------------------------------\n");
		}
	}

	sm->stop();
	delete sm;
	delete cfg;
	delete dm;
	
	return 0;
}
Exemplo n.º 2
0
void displayCallback(void) 
{
	static float lt = 0.0f;
	static uint64 frame = 0;

	GlutDisplaySystem* ds = (GlutDisplaySystem*)SystemManager::instance()->getDisplaySystem();
	Engine* as = ds->getApplicationServer();
	Renderer* ac = ds->getApplicationClient();

	// Compute dt.
	float t = (float)((double)clock() / CLOCKS_PER_SEC);
	UpdateContext uc;
	uc.dt = t - lt;
	lt = t;

	as->update(uc);
	//ac->update(uc);

	glClearColor(0, 0, 0, 0);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

	// setup the context viewport.
	DrawContext dc;
	DisplayTileConfig dtc(ds->getDisplayConfig());
	dtc.device = 0;
	//dtc.index = Vector2i::Zero();
	dtc.offset = Vector2i::Zero();
	dtc.pixelSize = ds->getCanvasSize();

	dc.frameNum = frame++;
	dc.tile = &dtc;
	dc.gpuContext = ds->getGpuContext();

	ds->updateProjectionMatrix();

	Camera* cam = Engine::instance()->getDefaultCamera();

	// Push observer matrix.
	glPushMatrix();
	AffineTransform3 mat = cam->getViewTransform();
	glLoadIdentity();
	glLoadMatrixd(mat.data());

	dc.viewport = Rect(0, 0, glutGet(GLUT_WINDOW_WIDTH), glutGet(GLUT_WINDOW_HEIGHT));
	glGetDoublev( GL_MODELVIEW_MATRIX, dc.modelview.data() );
	glGetDoublev( GL_PROJECTION_MATRIX, dc.projection.data() );

	//dc.drawBuffer = ds->getFrameBuffer();

	// Process events.
	ServiceManager* im = SystemManager::instance()->getServiceManager();
	int av = im->getAvailableEvents();
	if(av != 0)
	{
		Event evts[OMICRON_MAX_EVENTS];
		im->getEvents(evts, ServiceManager::MaxEvents);

		// Dispatch events to application server.
		for( int evtNum = 0; evtNum < av; evtNum++)
		{
			as->handleEvent(evts[evtNum]);
		}
	}

	dc.eye = DrawContext::EyeCyclop;
	dc.task = DrawContext::SceneDrawTask;
	ac->draw(dc);
	dc.task = DrawContext::OverlayDrawTask;
	ac->draw(dc);

	glPopMatrix();

	//glFlush();
	glutPostRedisplay();

	// poll the input manager for new events.
	im->poll();

	if(SystemManager::instance()->isExitRequested())
	{
		exit(0);
	}
}