acpi and mahaf: now set ModuleInitState to error if something fails (prevents a subsequent init from returning true and allowing its dependent to continue and crash into a wall)

wtime: "implement" CLOCK_MONOTONIC (that's what the timer already did,
anyhow)

main: move early init to GameSetup!EarlyInit (fixes atlas problem with
timer)

This was SVN commit r5101.
This commit is contained in:
janwas 2007-05-26 23:29:20 +00:00
parent 2348f71aea
commit c9f10be090
7 changed files with 42 additions and 24 deletions

View File

@ -245,7 +245,10 @@ bool acpi_Init()
return true;
if(!mahaf_Init())
{
ModuleSetError(&initState);
return false;
}
LatchAllTables();
return true;

View File

@ -261,7 +261,10 @@ bool mahaf_Init()
DWORD shareMode = 0;
hAken = CreateFile("\\\\.\\Aken", GENERIC_READ, shareMode, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
if(hAken == INVALID_HANDLE_VALUE)
{
ModuleSetError(&initState);
return false;
}
return true;
}

View File

@ -110,7 +110,7 @@ static uint MsFromTimespec(const timespec& ts)
int clock_gettime(clockid_t clock, struct timespec* ts)
{
debug_assert(clock == CLOCK_REALTIME);
debug_assert(clock == CLOCK_REALTIME || clock == CLOCK_MONOTONIC);
const i64 ns = CurrentSystemTime_ns();
*ts = TimespecFromNs(ns);
@ -120,7 +120,7 @@ int clock_gettime(clockid_t clock, struct timespec* ts)
int clock_getres(clockid_t clock, struct timespec* ts)
{
debug_assert(clock == CLOCK_REALTIME);
debug_assert(clock == CLOCK_REALTIME || clock == CLOCK_MONOTONIC);
const i64 ns = cpu_i64FromDouble(whrt_Resolution() * 1e9);
*ts = TimespecFromNs(ns);

View File

@ -41,7 +41,11 @@ extern int usleep(useconds_t us);
typedef enum
{
CLOCK_REALTIME
// in our implementation, these actually do the same thing
// (a timer that latches the system time at startup and uses the
// monotonic HRT to add elapsed time since then)
CLOCK_REALTIME,
CLOCK_MONOTONIC
}
clockid_t;

View File

@ -14,8 +14,8 @@ that of Atlas depending on commandline parameters.
#include "lib/precompiled.h"
#include "lib/input.h"
#include "lib/external_libraries/sdl.h"
#include "lib/timer.h"
#include "lib/external_libraries/sdl.h"
#include "lib/res/file/vfs.h"
#include "lib/res/sound/snd_mgr.h"
#include "lib/res/file/vfs_optimizer.h"
@ -39,10 +39,6 @@ that of Atlas depending on commandline parameters.
#include "sound/CMusicPlayer.h"
#include "gui/GUI.h"
#if OS_WIN
# include "lib/sysdep/win/wstartup.h"
#endif
#define LOG_CATEGORY "main"
extern bool g_TerrainModified;
@ -381,13 +377,7 @@ static void RunGameOrAtlas(int argc, char* argv[])
int main(int argc, char* argv[])
{
// If you ever want to catch a particular allocation:
//_CrtSetBreakAlloc(321);
// see discussion at declaration of wstartup_PreMainInit.
#if OS_WIN
wstartup_PreMainInit();
#endif
EarlyInit(); // must come at beginning of main
RunGameOrAtlas(argc, argv);

View File

@ -13,6 +13,9 @@
#include "lib/res/sound/snd_mgr.h"
#include "lib/res/graphics/tex.h"
#include "lib/res/graphics/cursor.h"
#if OS_WIN
# include "lib/sysdep/win/wstartup.h"
#endif
#include "ps/CConsole.h"
#include "ps/CLogger.h"
@ -95,9 +98,6 @@ ERROR_TYPE(System, RequiredExtensionsMissing);
#define LOG_CATEGORY "gamesetup"
static int SetVideoMode(int w, int h, int bpp, bool fullscreen)
{
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
@ -876,22 +876,34 @@ void Shutdown(uint flags)
TIMER_END("shutdown misc");
}
void Init(const CmdLineArgs& args, uint flags)
void EarlyInit()
{
const bool setup_vmode = (flags & INIT_HAVE_VMODE) == 0;
#if OS_WIN
// see discussion at declaration of wstartup_PreMainInit.
wstartup_PreMainInit(); // must come before any use of lib/sysdep/win
#endif
MICROLOG(L"Init");
MICROLOG(L"EarlyInit");
// If you ever want to catch a particular allocation:
//_CrtSetBreakAlloc(321);
debug_set_thread_name("main");
// add all debug_printf "tags" that we are interested in:
debug_filter_add("TIMER");
lockfree_Init();
timer_Init();
// Query CPU capabilities, possibly set some CPU-dependent flags
cpu_Init();
cpu_Init(); // must come after timer_Init
}
void Init(const CmdLineArgs& args, uint flags)
{
const bool setup_vmode = (flags & INIT_HAVE_VMODE) == 0;
MICROLOG(L"Init");
h_mgr_init();

View File

@ -18,6 +18,12 @@ extern void Render();
extern void RenderActor();
/**
* initialize global modules that are be needed before Init.
* must be called from the very beginning of main.
**/
extern void EarlyInit();
enum InitFlags
{
// avoid setting a video mode / initializing OpenGL; assume that has