Ejemplo n.º 1
0
void CJoystick::Initialise()
{
	bool joystickEnable = false;
	CFG_GET_USER_VAL("joystick.enable", Bool, joystickEnable);
	if (!joystickEnable)
		return;

	CFG_GET_USER_VAL("joystick.deadzone", Int, m_Deadzone);

	if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) < 0)
	{
		LOGERROR(L"InitInput: failed to initialise joystick");
		return;
	}

	int numJoysticks = SDL_NumJoysticks();

	LOGMESSAGE(L"Found %d joystick(s)", numJoysticks);

	for (int i = 0; i < numJoysticks; ++i)
		LOGMESSAGE(L"Joystick %d: %hs", i, SDL_JoystickName(i));

	if (numJoysticks)
	{
		SDL_JoystickEventState(SDL_ENABLE);

		// Always pick the first joystick, and assume that's the right one
		m_Joystick = SDL_JoystickOpen(0);
	}
}
Ejemplo n.º 2
0
void CVideoMode::ReadConfig()
{
	bool windowed = !m_ConfigFullscreen;
	CFG_GET_USER_VAL("windowed", Bool, windowed);
	m_ConfigFullscreen = !windowed;

	CFG_GET_USER_VAL("xres", Int, m_ConfigW);
	CFG_GET_USER_VAL("yres", Int, m_ConfigH);
	CFG_GET_USER_VAL("bpp", Int, m_ConfigBPP);
	CFG_GET_USER_VAL("force_s3tc_enable", Bool, m_ConfigForceS3TCEnable);
}
Ejemplo n.º 3
0
void CONFIG_Init(const CmdLineArgs& args)
{
    TIMER(L"CONFIG_Init");

    new CConfigDB;

    // Load the global, default config file
    g_ConfigDB.SetConfigFile(CFG_DEFAULT, L"config/default.cfg");
    g_ConfigDB.Reload(CFG_DEFAULT);	// 216ms
    // Try loading the local system config file (which doesn't exist by
    // default) - this is designed as a way of letting developers edit the
    // system config without accidentally committing their changes back to SVN.
    g_ConfigDB.SetConfigFile(CFG_SYSTEM, L"config/local.cfg");
    g_ConfigDB.Reload(CFG_SYSTEM);

    g_ConfigDB.SetConfigFile(CFG_USER, L"config/user.cfg");
    g_ConfigDB.Reload(CFG_USER);

    g_ConfigDB.SetConfigFile(CFG_MOD, L"config/mod.cfg");
    // No point in reloading mod.cfg here - we haven't mounted mods yet

    ProcessCommandLineArgs(args);

    // Initialise console history file
    int max_history_lines = 200;
    CFG_GET_USER_VAL("console.history.size", Int, max_history_lines);
    g_Console->UseHistoryFile(L"config/console.txt", max_history_lines);

    // Collect information from system.cfg, the profile file,
    // and any command-line overrides to fill in the globals.
    LoadGlobals();	// 64ms
}
Ejemplo n.º 4
0
// Fill in the globals from the config files.
static void LoadGlobals()
{
    CFG_GET_USER_VAL("vsync", Bool, g_VSync);

    CFG_GET_USER_VAL("nos3tc", Bool, g_NoGLS3TC);
    CFG_GET_USER_VAL("noautomipmap", Bool, g_NoGLAutoMipmap);
    CFG_GET_USER_VAL("novbo", Bool, g_NoGLVBO);
    CFG_GET_USER_VAL("pauseonfocusloss", Bool, g_PauseOnFocusLoss);
    CFG_GET_USER_VAL("shadows", Bool, g_Shadows);
    CFG_GET_USER_VAL("shadowpcf", Bool, g_ShadowPCF);
    CFG_GET_USER_VAL("fancywater", Bool, g_FancyWater);
    CFG_GET_USER_VAL("renderpath", String, g_RenderPath);

    CFG_GET_USER_VAL("lodbias", Float, g_LodBias);

    float gain = -1.0f;
    CFG_GET_USER_VAL("sound.mastergain", Float, gain);
    if(gain >= 0.0f)
        WARN_IF_ERR(snd_set_master_gain(gain));
}
Ejemplo n.º 5
0
void InitGraphics(const CmdLineArgs& args, int flags)
{
	const bool setup_vmode = (flags & INIT_HAVE_VMODE) == 0;

	if(setup_vmode)
	{
		InitSDL();

		if (!g_VideoMode.InitSDL())
			throw PSERROR_System_VmodeFailed(); // abort startup

#if !SDL_VERSION_ATLEAST(2, 0, 0)
		SDL_WM_SetCaption("0 A.D.", "0 A.D.");
#endif
	}

	RunHardwareDetection();

	tex_codec_register_all();

	const int quality = SANE_TEX_QUALITY_DEFAULT;	// TODO: set value from config file
	SetTextureQuality(quality);

	ogl_WarnIfError();

	// Optionally start profiler GPU timings automatically
	// (By default it's only enabled by a hotkey, for performance/compatibility)
	bool profilerGPUEnable = false;
	CFG_GET_USER_VAL("profiler2.gpu.autoenable", Bool, profilerGPUEnable);
	if (profilerGPUEnable)
		g_Profiler2.EnableGPU();

	if(!g_Quickstart)
	{
		WriteSystemInfo();
		// note: no longer vfs_display here. it's dog-slow due to unbuffered
		// file output and very rarely needed.
	}

	if(g_DisableAudio)
	{
		// speed up startup by disabling all sound
		// (OpenAL init will be skipped).
		// must be called before first snd_open.
		g_SoundManager->SetEnabled(false);
	}

	g_GUI = new CGUIManager(g_ScriptingHost.GetScriptInterface());

	// (must come after SetVideoMode, since it calls ogl_Init)
	const char* missing = ogl_HaveExtensions(0,
		"GL_ARB_multitexture",
		"GL_EXT_draw_range_elements",
		"GL_ARB_texture_env_combine",
		"GL_ARB_texture_env_dot3",
		NULL);
	if(missing)
	{
		wchar_t buf[500];
		swprintf_s(buf, ARRAY_SIZE(buf),
			L"The %hs extension doesn't appear to be available on your computer."
			L" The game may still work, though - you are welcome to try at your own risk."
			L" If not or it doesn't look right, upgrade your graphics card.",
			missing
		);
		DEBUG_DISPLAY_ERROR(buf);
		// TODO: i18n
	}

	if (!ogl_HaveExtension("GL_ARB_texture_env_crossbar"))
	{
		DEBUG_DISPLAY_ERROR(
			L"The GL_ARB_texture_env_crossbar extension doesn't appear to be available on your computer."
			L" Shadows are not available and overall graphics quality might suffer."
			L" You are advised to try installing newer drivers and/or upgrade your graphics card.");
		g_Shadows = false;
	}

	ogl_WarnIfError();
	InitRenderer();

	InitInput();

	ogl_WarnIfError();

	try
	{
		if (!Autostart(args))
		{
			const bool setup_gui = ((flags & INIT_NO_GUI) == 0);
			InitPs(setup_gui, L"page_pregame.xml", JSVAL_VOID);
		}
	}
	catch (PSERROR_Game_World_MapLoadFailed e)
	{
		// Map Loading failed

		// Start the engine so we have a GUI
		InitPs(true, L"page_pregame.xml", JSVAL_VOID);

		// Call script function to do the actual work
		//	(delete game data, switch GUI page, show error, etc.)
		CancelLoad(CStr(e.what()).FromUTF8());
	}
}
Ejemplo n.º 6
0
void Init(const CmdLineArgs& args, int UNUSED(flags))
{
	h_mgr_init();

	// Do this as soon as possible, because it chdirs
	// and will mess up the error reporting if anything
	// crashes before the working directory is set.
	InitVfs(args);

	// This must come after VFS init, which sets the current directory
	// (required for finding our output log files).
	g_Logger = new CLogger;

	// Special command-line mode to dump the entity schemas instead of running the game.
	// (This must be done after loading VFS etc, but should be done before wasting time
	// on anything else.)
	if (args.Has("dumpSchema"))
	{
		CSimulation2 sim(NULL, NULL);
		sim.LoadDefaultScripts();
		std::ofstream f("entity.rng", std::ios_base::out | std::ios_base::trunc);
		f << sim.GenerateSchema();
		std::cout << "Generated entity.rng\n";
		exit(0);
	}

	// override ah_translate with our i18n code.
	AppHooks hooks = {0};
	hooks.translate = psTranslate;
	hooks.translate_free = psTranslateFree;
	app_hooks_update(&hooks);

	// Set up the console early, so that debugging
	// messages can be logged to it. (The console's size
	// and fonts are set later in InitPs())
	g_Console = new CConsole();

	CNetHost::Initialize();

	new CProfileViewer;
	new CProfileManager;	// before any script code

	g_ScriptStatsTable = new CScriptStatsTable;
	g_ProfileViewer.AddRootTable(g_ScriptStatsTable);

	g_SoundManager = new CSoundManager();

	InitScripting();	// before GUI

	// g_ConfigDB, command line args, globals
	CONFIG_Init(args);

	// Optionally start profiler HTTP output automatically
	// (By default it's only enabled by a hotkey, for security/performance)
	bool profilerHTTPEnable = false;
	CFG_GET_USER_VAL("profiler2.http.autoenable", Bool, profilerHTTPEnable);
	if (profilerHTTPEnable)
		g_Profiler2.EnableHTTP();

	if (!g_Quickstart)
		g_UserReporter.Initialize(); // after config

	PROFILE2_EVENT("Init finished");
}
Ejemplo n.º 7
0
void Render()
{
	PROFILE3("render");

	g_SoundManager->IdleTask();

	ogl_WarnIfError();

	g_Profiler2.RecordGPUFrameStart();

	ogl_WarnIfError();

	CStr skystring = "255 0 255";
	CFG_GET_USER_VAL("skycolor", String, skystring);
	CColor skycol;
	GUI<CColor>::ParseString(skystring.FromUTF8(), skycol);
	g_Renderer.SetClearColor(skycol.AsSColor4ub());

	// prepare before starting the renderer frame
	if (g_Game && g_Game->IsGameStarted())
		g_Game->GetView()->BeginFrame();

	// start new frame
	g_Renderer.BeginFrame();

	ogl_WarnIfError();

	if (g_Game && g_Game->IsGameStarted())
		g_Game->GetView()->Render();

	ogl_WarnIfError();

	g_Renderer.RenderTextOverlays();

	if (g_DoRenderGui)
		g_GUI->Draw();

	ogl_WarnIfError();

	// If we're in Atlas game view, render special overlays (e.g. editor bandbox)
	if (g_AtlasGameLoop && g_AtlasGameLoop->view)
	{
		g_AtlasGameLoop->view->DrawOverlays();
		ogl_WarnIfError();
	}

	// Text:

 	glDisable(GL_DEPTH_TEST);

	g_Console->Render();

	ogl_WarnIfError();

	if (g_DoRenderLogger)
		g_Logger->Render();

	ogl_WarnIfError();

	// Profile information

	g_ProfileViewer.RenderProfile();

	ogl_WarnIfError();

	// Draw the cursor (or set the Windows cursor, on Windows)
	if (g_DoRenderCursor)
	{
		PROFILE3_GPU("cursor");
		CStrW cursorName = g_CursorName;
		if (cursorName.empty())
		{
			cursor_draw(g_VFS, NULL, g_mouse_x, g_yres-g_mouse_y, false);
		}
		else
		{
			bool forceGL = false;
			CFG_GET_USER_VAL("nohwcursor", Bool, forceGL);

#if CONFIG2_GLES
#warning TODO: implement cursors for GLES
#else
			// set up transform for GL cursor
			glMatrixMode(GL_PROJECTION);
			glPushMatrix();
			glLoadIdentity();
			glMatrixMode(GL_MODELVIEW);
			glPushMatrix();
			glLoadIdentity();
			CMatrix3D transform;
			transform.SetOrtho(0.f, (float)g_xres, 0.f, (float)g_yres, -1.f, 1000.f);
			glLoadMatrixf(&transform._11);
#endif

			if (cursor_draw(g_VFS, cursorName.c_str(), g_mouse_x, g_yres-g_mouse_y, forceGL) < 0)
				LOGWARNING(L"Failed to draw cursor '%ls'", cursorName.c_str());

#if CONFIG2_GLES
#warning TODO: implement cursors for GLES
#else
			// restore transform
			glMatrixMode(GL_PROJECTION);
			glPopMatrix();
			glMatrixMode(GL_MODELVIEW);
			glPopMatrix();
#endif
		}
	}

	glEnable(GL_DEPTH_TEST);

	g_Renderer.EndFrame();

	PROFILE2_ATTR("draw calls: %d", (int)g_Renderer.GetStats().m_DrawCalls);
	PROFILE2_ATTR("terrain tris: %d", (int)g_Renderer.GetStats().m_TerrainTris);
	PROFILE2_ATTR("water tris: %d", (int)g_Renderer.GetStats().m_WaterTris);
	PROFILE2_ATTR("model tris: %d", (int)g_Renderer.GetStats().m_ModelTris);
	PROFILE2_ATTR("overlay tris: %d", (int)g_Renderer.GetStats().m_OverlayTris);
	PROFILE2_ATTR("blend splats: %d", (int)g_Renderer.GetStats().m_BlendSplats);
	PROFILE2_ATTR("particles: %d", (int)g_Renderer.GetStats().m_Particles);

	ogl_WarnIfError();

	g_Profiler2.RecordGPUFrameEnd();

	ogl_WarnIfError();
}