Exemplo n.º 1
0
void TestController::menuCallback(cocos2d::CCObject *pSender)
{
    CCMenuItem* pMenuItem = (CCMenuItem *)(pSender);
    int nIdx = pMenuItem->getTag() - 10000;
    CCLOG("click menu index = %d", nIdx);
    // create the test scene and run it
    TestBaseLayer* layer = CreateTestScene(nIdx);
    if (layer)
    {
        layer->runThisLayer();
    }
    
}
Exemplo n.º 2
0
void TestController::menuCallback(CCObject * pSender)
{
    // get the userdata, it's the index of the menu item clicked
    CCMenuItem* pMenuItem = (CCMenuItem *)(pSender);
    int nIdx = pMenuItem->getZOrder() - 10000;
    // create the test scene and run it
    TestScene* pScene = CreateTestScene(nIdx);
    if (pScene)
    {
        pScene->runThisTest();
        pScene->release();
    }
}
Exemplo n.º 3
0
	void Main(PlatformAPI *api)
	{
		// Application settings
		Application app;
		app.api = api;
		SetApplicationTitle(api, "CPU Rasterizer");

		// Mouse setup
		app.mouse_exclusive = true;
		app.mouse_sensitivity = 0.8f * 0.0022f; // Sensitivity * source engine scale

		// Setup player properties
		app.player_yaw = 0.0f;
		app.player_pitch = 0.0f;
		app.player_flags = 0;

		// Setup camera
		app.camera.pos = float3(0.0f, 0.0f, -8.0f);
		app.camera.fov = Tau * 0.25f;

		// Setup scene
		CreateTestScene(app.scene);
		
		// Set events
		SetKeyboardEvent(api, &app, OnKeyboardEvent);
		SetMouseEvent(api, &app, OnMouseEvent);
		SetMouseCaptureMode(api, MouseCaptureModeExclusive);

		// Create software renderer
		app.renderer = CreateSoftwareRenderer(api, 1280, 720, false);

		// Load default font.
		app.font = CreateFontFromFile("C:\\Windows\\Fonts\\calibrib.ttf", 18.0f);

		// Initialize the rasterizer data
		{
			app.frame_info = NULL;

			// Default framebuffer
			app.framebuffer.width = 1280;
			app.framebuffer.height = 720;
			U32 size = GetRequiredMemoryAmount(app.framebuffer, true, true);
			Initialize(app.framebuffer, malloc(size), true, true);

			// Threads
			CreateRasterizerThreads(app);
		}

		// Frame update loop
		U64 frame_start_time = GetTime(api);
		app.frame_delta = 0.0001f;
		while (Update(api))
		{
			// Apply player rotation to camera.
			app.camera.axis[0] = float3(1.0f, 0.0f, 0.0f);
			app.camera.axis[1] = float3(0.0f, 1.0f, 0.0f);
			app.camera.axis[2] = float3(0.0f, 0.0f, 1.0f);
			Rotate(app.camera.axis[0], float3(1.0f, 0.0f, 0.0f), app.player_pitch);
			Rotate(app.camera.axis[1], float3(1.0f, 0.0f, 0.0f), app.player_pitch);
			Rotate(app.camera.axis[2], float3(1.0f, 0.0f, 0.0f), app.player_pitch);
			Rotate(app.camera.axis[0], float3(0.0f, 1.0f, 0.0f), app.player_yaw);
			Rotate(app.camera.axis[1], float3(0.0f, 1.0f, 0.0f), app.player_yaw);
			Rotate(app.camera.axis[2], float3(0.0f, 1.0f, 0.0f), app.player_yaw);

			// Apply player movement to camera
			float3 player_velocity = 0.0f;
			if (app.player_flags & PlayerFlagMoveForward)
				player_velocity += app.camera.axis[2];
			if (app.player_flags & PlayerFlagMoveBackward)
				player_velocity -= app.camera.axis[2];
			if (app.player_flags & PlayerFlagMoveRight)
				player_velocity -= app.camera.axis[0];
			if (app.player_flags & PlayerFlagMoveLeft)
				player_velocity += app.camera.axis[0];
			if (Dot(player_velocity, player_velocity) != 0.0f)
				Normalize(player_velocity);
			player_velocity *= 5.0f * app.frame_delta;
			app.camera.pos += player_velocity;

			// Render the frame
			LockBufferInfo frame_info;
			LockBuffer(app.renderer, frame_info);
			RenderFrame(app, frame_info);
			PrintDebugStats(app, frame_info);
			UnlockBuffer(app.renderer);

			// Calculate frame delta time
			U64 time = GetTime(api);
			U64 delta = time - frame_start_time;
			frame_start_time = time;
			app.frame_delta = float(delta) / float(U64(1) << U64(32));
		}
	}