win32stuff.cpp 1.76 KB
#include "dependencies.h"
#include "AnubisSupport.h"
#include "DebugLog.h"
#include <assert.h>
#include <string>

int kernelInit(void)
{

  WSADATA wsadata; 

 /* Open console for output  */
// AllocConsole();

  assert(sizeof(long) == 4); 
   
  if (WSAStartup(MAKEWORD(2,2),&wsadata) != 0)
    {
      LOGERROR("Winsock.dll not found."); 
      my_exit(1); 
    }
 return 1;
}

const char * getpass(const char * in)
{
 return "";
}


void my_exit(int returnCode)
{
// WaitForKeyboard();
 exit(returnCode); 
}

void WaitForKeyboard(void)
{
   INPUT_RECORD inpRecord;
  DWORD readRecord = 0;
  BOOL quit = FALSE;

  while ( quit == FALSE) 
  {
   ReadConsoleInput(GetStdHandle(STD_INPUT_HANDLE), &inpRecord, 1, &readRecord);
   if(inpRecord.EventType == KEY_EVENT )
    quit = TRUE;
  }

}

void common_sleep(unsigned int  mseconds )
{
    Sleep(mseconds);
}

   
/* Time functions */

static int64 startclock = 0;  // we want a start time
static double rate_inv = 0;

status_t
initftime(void) {
	int64 rate;
	
	// we need the accuracy
	if(!QueryPerformanceFrequency((LARGE_INTEGER*)&rate)) {
		return B_ERROR; // win errors
	}
	
	// usually the rate will be the CPU clock
	if(!rate) {
		return B_ERROR;
	}
	
	rate_inv = 1.0 / (double)rate;		// in second / ticks
	rate_inv = rate_inv * 1000000L;		// in µsecond / ticks
	
	if(!QueryPerformanceCounter((LARGE_INTEGER*)&startclock)) {
		return B_ERROR; // win errors
	}
	
	return B_OK; // there is a clock
}
// you would have to start up with initftime() at the beginning
// of the game. And check for errors


bigtime_t
system_time (void)     /* time since booting in microseconds */
{
	// by dividing by its rate you get accurate µseconds
	int64 endclock;
	QueryPerformanceCounter((LARGE_INTEGER*)&endclock);
	return (bigtime_t)(endclock*rate_inv);
}