Ejemplo n.º 1
0
//Not terribly sure how this function is suppose to work,
//but jday helped to figure most of it out
int getch(void)
{
 refresh();
 InvalidateRect(WindowHandle,NULL,true);
 lastchar=ERR;//ERR=-1
    if (inputdelay < 0)
    {
        do
        {
            CheckMessages();
            if (lastchar!=ERR) break;
            MsgWaitForMultipleObjects(0, NULL, FALSE, 50, QS_ALLEVENTS);//low cpu wait!
        }
        while (lastchar==ERR);
    }
    else if (inputdelay > 0)
    {
        unsigned long starttime=GetTickCount();
        unsigned long endtime;
        do
        {
            CheckMessages();        //MsgWaitForMultipleObjects won't work very good here
            endtime=GetTickCount(); //it responds to mouse movement, and WM_PAINT, not good
            if (lastchar!=ERR) break;
            Sleep(2);
        }
        while (endtime<(starttime+inputdelay));
    }
    else
    {
        CheckMessages();
    };
    Sleep(25);
    return lastchar;
};
Ejemplo n.º 2
0
// This is how we're actually going to handle input events, SDL getch
// is simply a wrapper around this.
input_event input_manager::get_input_event(WINDOW *win) {
    // standards note: getch is sometimes required to call refresh
    // see, e.g., http://linux.die.net/man/3/getch
    // so although it's non-obvious, that refresh() call (and maybe InvalidateRect?) IS supposed to be there

    if(win == NULL) win = mainwin;

    wrefresh(win);
    lastchar=ERR;//ERR=-1
    if (inputdelay < 0)
    {
        do
        {
            CheckMessages();
            if (lastchar!=ERR) break;
            SDL_Delay(1);
        }
        while (lastchar==ERR);
    }
    else if (inputdelay > 0)
    {
        unsigned long starttime=SDL_GetTicks();
        unsigned long endtime;
        do
        {
            CheckMessages();
            endtime=SDL_GetTicks();
            if (lastchar!=ERR) break;
            SDL_Delay(1);
        }
        while (endtime<(starttime+inputdelay));
    }
    else
    {
        CheckMessages();
    }

    input_event rval;

    if(lastchar == ERR) {
        rval.type = CATA_INPUT_ERROR;
    } else if(lastchar_isbutton) {
        rval.type = CATA_INPUT_GAMEPAD;
        rval.add_input(lastchar);
    } else if(lastchar_is_mouse) {
        rval.type = CATA_INPUT_MOUSE;
        rval.add_input(lastchar);
        SDL_GetMouseState(&rval.mouse_x, &rval.mouse_y);
    } else {
        rval.type = CATA_INPUT_KEYBOARD;
        rval.add_input(lastchar);
    }

    return rval;
}
Ejemplo n.º 3
0
int GenerateList(HWND hList, HWND hStatus)
{
	TFlashHeader *headers;
	uint32_t i;
	int side = 0, empty = 0;
	char str[128];

	ListView_DeleteAllItems(hList);
	EnableWindow(hList, FALSE);
	SetWindowText(hStatus, "Reading disk headers...");
	CheckMessages();

	fdsemu->dev->FlashUtil->ReadHeaders();
	headers = fdsemu->dev->FlashUtil->GetHeaders();
	if (headers == 0) {
		return(-1);
	}

	for (i = 0; i < fdsemu->dev->Slots; i++) {
		TFlashHeader *header = &headers[i];
		uint8_t *buf = headers[i].filename;

		//empty slot
		if (buf[0] == 0xFF) {
			empty++;
			continue;
		}

		//this slot has valid ownerid/nextid
		if (header->flags & 0x20) {

			//first disk image of a set
			if (header->ownerid == i) {
				InsertListViewItem(hList, (char*)buf, i);
			}
		}

		else {
			//filename is here
			if (buf[0] != 0) {
				InsertListViewItem(hList, (char*)buf, i);
			}
		}
	}

	ListView_SortItems(hList, CompareFunc, 0);
	EnableWindow(hList, TRUE);

	//update teh status bar
	if (empty >= 0) {
		sprintf(str, "%d slots used, %d remaining.", fdsemu->dev->Slots - empty, empty);
	}
	else {
		sprintf(str, "Error reading flash headers.");
	}
	SetWindowText(hStatus, str);


	return(empty);
}
Ejemplo n.º 4
0
void WriteCallback(void *user, int x, int y)
{
	/*
	x = 0, number of sides total, called before anything is written
	x = 1, current side number writing, calling before that side has started
	x = 2, write address of current side, called periodically
	*/
	HWND hProgress = (HWND)user;
	static int curside = 0;

	CheckMessages();

	//number of sides total
	if (x == 0) {
		SendMessage(hProgress, PBM_SETRANGE, 0, MAKELPARAM(0, (y * 0x10000) / 0x100));
		SendMessage(hProgress, PBM_SETSTEP, (WPARAM)1, 0);
		curside = 0;
	}

	else if (x == 1) {
		curside = y;
	}

	else if (x == 2) {
		SendMessage(hProgress, PBM_SETPOS, (WPARAM)((y + (curside * 0x10000)) / 0x100), 0);
	}

}
Ejemplo n.º 5
0
void WriteDiskImages(HWND hWnd, CStringList *sl)
{
	int i;
	HWND hDlg;
	HWND hList, hProgress, hProgress2;

	BOOL b = EnableWindow(hWnd, FALSE);
	hDlg = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_WRITEDIALOG), hWnd, reinterpret_cast<DLGPROC>(WriteImagesDlg), (LPARAM)sl);
	hList = GetDlgItem(hDlg, IDC_WRITELIST);
	hProgress = GetDlgItem(hDlg, IDC_PROGRESS);
	hProgress2 = GetDlgItem(hDlg, IDC_PROGRESS2);

	SendMessage(hProgress2, PBM_SETRANGE, 0, MAKELPARAM(0, sl->Count()));
	SendMessage(hProgress2, PBM_SETSTEP, (WPARAM)1, 0);

	ShowWindow(hDlg, SW_SHOW);
	for (i = 0; i < sl->Count(); i++) {
		SendMessage(hProgress2, PBM_SETPOS, (WPARAM)(i), 0);
		SendMessage(hList, LB_ADDSTRING, 0, (WPARAM)sl->Get(i));
		CheckMessages();
		fdsemu->WriteFlash(sl->Get(i), WriteCallback, (HWND)hProgress);
//		fdsemu->dev->FlashUtil->ReadHeaders();
	}
	DestroyWindow(hDlg);
	EnableWindow(hWnd, TRUE);
	SetActiveWindow(hWnd);
}
Ejemplo n.º 6
0
bool	Window::UpdateWindow() {
	Keyboard::instance->UpdateHolds();
	Mouse::instance->UpdateHolds();

	MSG		msg;
	while(PeekMessage(&msg,windowHandle,0,0,PM_REMOVE)) {
		CheckMessages(msg); 
	}

	return !forceQuit;
}
Ejemplo n.º 7
0
//Not terribly sure how this function is suppose to work,
//but jday helped to figure most of it out
int getch(void)
{
 // standards note: getch is sometimes required to call refresh
 // see, e.g., http://linux.die.net/man/3/getch
 // so although it's non-obvious, that refresh() call (and maybe InvalidateRect?) IS supposed to be there
 refresh();
 InvalidateRect(WindowHandle,NULL,true);
 lastchar=ERR;//ERR=-1
    if (inputdelay < 0)
    {
        do
        {
            CheckMessages();
            if (lastchar!=ERR) break;
            MsgWaitForMultipleObjects(0, NULL, FALSE, 50, QS_ALLEVENTS);//low cpu wait!
        }
        while (lastchar==ERR);
    }
    else if (inputdelay > 0)
    {
        unsigned long starttime=GetTickCount();
        unsigned long endtime;
        do
        {
            CheckMessages();        //MsgWaitForMultipleObjects won't work very good here
            endtime=GetTickCount(); //it responds to mouse movement, and WM_PAINT, not good
            if (lastchar!=ERR) break;
            Sleep(2);
        }
        while (endtime<(starttime+inputdelay));
    }
    else
    {
        CheckMessages();
    };
    Sleep(25);
    return lastchar;
};
Ejemplo n.º 8
0
//Not terribly sure how this function is suppose to work,
//but jday helped to figure most of it out
int curses_getch(WINDOW* win)
{
    // standards note: getch is sometimes required to call refresh
    // see, e.g., http://linux.die.net/man/3/getch
    // so although it's non-obvious, that refresh() call (and maybe InvalidateRect?) IS supposed to be there
    uint64_t Frequency;
    QueryPerformanceFrequency((PLARGE_INTEGER)&Frequency);
    wrefresh(win);
    InvalidateRect(WindowHandle,NULL,true);
    lastchar = ERR;
    if (inputdelay < 0)
    {
        for (; lastchar==ERR; Sleep(1))
            CheckMessages();
    }
    else if (inputdelay > 0)
    {
        for (uint64_t t0=GetPerfCount(), t1=0; t1 < (t0 + inputdelay*Frequency/1000); t1=GetPerfCount())
        {
            CheckMessages();
            if (lastchar!=ERR) break;
            Sleep(1);
        }
    }
    else
    {
        CheckMessages();
    };

    if (lastchar!=ERR && OPTIONS["HIDE_CURSOR"] == "hidekb" && CursorVisible) {
        CursorVisible = false;
        ShowCursor(false);
    }

    return lastchar;
}
Ejemplo n.º 9
0
//Ported from windows and copied comments as well
//Not terribly sure how this function is suppose to work,
//but jday helped to figure most of it out
int curses_getch(WINDOW* win)
{
	// standards note: getch is sometimes required to call refresh
	// see, e.g., http://linux.die.net/man/3/getch
	// so although it's non-obvious, that refresh() call (and maybe InvalidateRect?) IS supposed to be there
	wrefresh(win);
	lastchar=ERR;//ERR=-1
    if (inputdelay < 0)
	{
        do
        {
            CheckMessages();
            if (lastchar!=ERR) break;
            SDL_Delay(1);
        }
        while (lastchar==ERR);
	}
    else if (inputdelay > 0)
	{
        unsigned long starttime=SDL_GetTicks();
        unsigned long endtime;
        do
        {
            CheckMessages();
            endtime=SDL_GetTicks();
            if (lastchar!=ERR) break;
            SDL_Delay(1);
        }
        while (endtime<(starttime+inputdelay));
	}
	else
	{
		CheckMessages();
	}
    return lastchar;
}
Ejemplo n.º 10
0
bool	Window::UpdateWindow() {
	MSG		msg;

	float diff = timer->GetMS()-elapsedMS;

	Window::GetMouse()->UpdateDoubleClick(diff);

	Window::GetKeyboard()->UpdateHolds();
	Window::GetMouse()->UpdateHolds();

	while(PeekMessage(&msg,windowHandle,0,0,PM_REMOVE)) {
		CheckMessages(msg); 
	}

	elapsedMS = timer->GetMS();

	return !forceQuit;
}
Ejemplo n.º 11
0
bool RunDemo(SD3dDemo _demo)
{
	SetupWindow();
	_demo.m_pInit();

	bool bQuit = false;
	while(!bQuit)
	{
		CheckMessages(bQuit);

		if(!bQuit)
		{
			_demo.m_pRender();
		}
	}

	_demo.m_pCleanUp();
	CleanUpWindow();

	return true;
}
Ejemplo n.º 12
0
void Engine::MainLoop() {
    CDEBUG("mainloop");
    // static int numframes, t = 0, fps = 0;                           // frame counter stuff (Why do these need to be static?)

    ScopedPtr<Ika::Font> font;
    try {
        font = new Ika::Font("system.fnt", video);
    } catch (Ika::FontException) {
        font = 0;
        _showFramerate = false;
    }

    int now = GetTime();
    SyncTime();

    for (;;) {
        CheckMessages();

        int skipcount = 0;

        while (
            (_oldTime < now) && 
            (skipcount <= _frameSkip)) {
            GameTick();
            _oldTime++;
            skipcount++;
        }

        _oldTime = now;
        now = GetTime();

        Render();

        if (_showFramerate) {
            font->PrintString(0, 0, va("Fps: %i", video->GetFrameRate()));
        }

        video->ShowPage();
    }
}
Ejemplo n.º 13
0
//Basic Init, create the font, backbuffer, etc
WINDOW *curses_init(void)
{
   // _windows = new WINDOW[20];         //initialize all of our variables
    lastchar=-1;
    inputdelay=-1;

    int fontsize = 16;
    std::string typeface;
    int map_fontwidth = 8;
    int map_fontheight = 16;
    int map_fontsize = 16;
    std::string map_typeface;
    int overmap_fontwidth = 8;
    int overmap_fontheight = 16;
    int overmap_fontsize = 16;
    std::string overmap_typeface;
    bool fontblending;

    std::ifstream jsonstream(FILENAMES["fontdata"].c_str(), std::ifstream::binary);
    if (jsonstream.good()) {
        JsonIn json(jsonstream);
        JsonObject config = json.get_object();
        // fontsize, fontblending, map_* are ignored in wincurse.
        fontwidth = config.get_int("fontwidth", fontwidth);
        fontheight = config.get_int("fontheight", fontheight);
        typeface = config.get_string("typeface", typeface);
        jsonstream.close();
    } else { // User fontdata is missed. Try to load legacy fontdata.
        // Get and save all values. With unused.
        std::ifstream InStream(FILENAMES["legacy_fontdata"].c_str(), std::ifstream::binary);
        if(InStream.good()) {
            JsonIn jIn(InStream);
            JsonObject config = jIn.get_object();
            fontwidth = config.get_int("fontwidth", fontwidth);
            fontheight = config.get_int("fontheight", fontheight);
            fontsize = config.get_int("fontsize", fontsize);
            typeface = config.get_string("typeface", typeface);
            map_fontwidth = config.get_int("map_fontwidth", fontwidth);
            map_fontheight = config.get_int("map_fontheight", fontheight);
            map_fontsize = config.get_int("map_fontsize", fontsize);
            map_typeface = config.get_string("map_typeface", typeface);
            overmap_fontwidth = config.get_int("overmap_fontwidth", fontwidth);
            overmap_fontheight = config.get_int("overmap_fontheight", fontheight);
            overmap_fontsize = config.get_int("overmap_fontsize", fontsize);
            overmap_typeface = config.get_string("overmap_typeface", typeface);
            InStream.close();
            // Save legacy as user fontdata.
            assure_dir_exist(FILENAMES["config_dir"]);
            std::ofstream OutStream(FILENAMES["fontdata"].c_str(), std::ofstream::binary);
            if(!OutStream.good()) {
                DebugLog( D_ERROR, DC_ALL ) << "Can't save user fontdata file.\n"
                << "Check permissions for: " << FILENAMES["fontdata"].c_str();
                return NULL;
            }
            JsonOut jOut(OutStream, true); // pretty-print
            jOut.start_object();
            jOut.member("fontblending", fontblending);
            jOut.member("fontwidth", fontwidth);
            jOut.member("fontheight", fontheight);
            jOut.member("fontsize", fontsize);
            jOut.member("typeface", typeface);
            jOut.member("map_fontwidth", map_fontwidth);
            jOut.member("map_fontheight", map_fontheight);
            jOut.member("map_fontsize", map_fontsize);
            jOut.member("map_typeface", map_typeface);
            jOut.member("overmap_fontwidth", overmap_fontwidth);
            jOut.member("overmap_fontheight", overmap_fontheight);
            jOut.member("overmap_fontsize", overmap_fontsize);
            jOut.member("overmap_typeface", overmap_typeface);
            jOut.end_object();
            OutStream << "\n";
            OutStream.close();
        } else {
            DebugLog( D_ERROR, DC_ALL ) << "Can't load fontdata files.\n"
            << "Check permissions for:\n" << FILENAMES["legacy_fontdata"].c_str() << "\n"
            << FILENAMES["fontdata"].c_str() << "\n";
            return NULL;
        }
    }

    halfwidth=fontwidth / 2;
    halfheight=fontheight / 2;
    WindowWidth= OPTIONS["TERMINAL_X"] * fontwidth;
    WindowHeight = OPTIONS["TERMINAL_Y"] * fontheight;

    WinCreate();    //Create the actual window, register it, etc
    timeBeginPeriod(1); // Set Sleep resolution to 1ms
    CheckMessages();    //Let the message queue handle setting up the window

    WindowDC   = GetDC(WindowHandle);
    backbuffer = CreateCompatibleDC(WindowDC);

    BITMAPINFO bmi = BITMAPINFO();
    bmi.bmiHeader.biSize         = sizeof(BITMAPINFOHEADER);
    bmi.bmiHeader.biWidth        = WindowWidth;
    bmi.bmiHeader.biHeight       = -WindowHeight;
    bmi.bmiHeader.biPlanes       = 1;
    bmi.bmiHeader.biBitCount     = 8;
    bmi.bmiHeader.biCompression  = BI_RGB; // Raw RGB
    bmi.bmiHeader.biSizeImage    = WindowWidth * WindowHeight * 1;
    bmi.bmiHeader.biClrUsed      = 16; // Colors in the palette
    bmi.bmiHeader.biClrImportant = 16; // Colors in the palette
    backbit = CreateDIBSection(0, &bmi, DIB_RGB_COLORS, (void**)&dcbits, NULL, 0);
    DeleteObject(SelectObject(backbuffer, backbit));//load the buffer into DC

    // Load private fonts
    if (SetCurrentDirectoryW(L"data\\font")){
        WIN32_FIND_DATA findData;
        for (HANDLE findFont = FindFirstFileW(L".\\*", &findData); findFont != INVALID_HANDLE_VALUE; )
        {
            if (!(findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)){ // Skip folders
                AddFontResourceExW(findData.cFileName, FR_PRIVATE,NULL);
            }
            if (!FindNextFile(findFont, &findData)){
                FindClose(findFont);
                break;
            }
        }
        SetCurrentDirectoryW(L"..\\..");
    }

    // Use desired font, if possible
    font = CreateFontW(fontheight, fontwidth, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE,
                      DEFAULT_CHARSET, OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,
                      PROOF_QUALITY, FF_MODERN, widen(typeface).c_str());

    SetBkMode(backbuffer, TRANSPARENT);//Transparent font backgrounds
    SelectObject(backbuffer, font);//Load our font into the DC
//    WindowCount=0;

    init_colors();

    mainwin = newwin(OPTIONS["TERMINAL_Y"],OPTIONS["TERMINAL_X"],0,0);
    return mainwin;   //create the 'stdscr' window and return its ref
}
Ejemplo n.º 14
0
//Basic Init, create the font, backbuffer, etc
WINDOW *curses_init(void)
{
   // _windows = new WINDOW[20];         //initialize all of our variables
    lastchar=-1;
    inputdelay=-1;

    std::string typeface;
    char * typeface_c = 0;
    std::ifstream fin;
    fin.open("data\\FONTDATA");
    if (!fin.is_open()){
        MessageBox(WindowHandle, "Failed to open FONTDATA, loading defaults.", NULL, 0);
        fontheight = 16;
        fontwidth  = 8;
    } else {
        getline(fin, typeface);
        typeface_c = new char [typeface.size()+1];
        strcpy (typeface_c, typeface.c_str());
        fin >> fontwidth;
        fin >> fontheight;
        if ((fontwidth <= 4) || (fontheight <=4)){
            MessageBox(WindowHandle, "Invalid font size specified!", NULL, 0);
            fontheight = 16;
            fontwidth  = 8;
        }
    }

    halfwidth=fontwidth / 2;
    halfheight=fontheight / 2;
    WindowWidth= (55 + (OPTIONS["VIEWPORT_X"] * 2 + 1)) * fontwidth;
    WindowHeight = (OPTIONS["VIEWPORT_Y"] * 2 + 1) *fontheight;

    WinCreate();    //Create the actual window, register it, etc
    timeBeginPeriod(1); // Set Sleep resolution to 1ms
    CheckMessages();    //Let the message queue handle setting up the window

    WindowDC   = GetDC(WindowHandle);
    backbuffer = CreateCompatibleDC(WindowDC);

    BITMAPINFO bmi = BITMAPINFO();
    bmi.bmiHeader.biSize         = sizeof(BITMAPINFOHEADER);
    bmi.bmiHeader.biWidth        = WindowWidth;
    bmi.bmiHeader.biHeight       = -WindowHeight;
    bmi.bmiHeader.biPlanes       = 1;
    bmi.bmiHeader.biBitCount     = 8;
    bmi.bmiHeader.biCompression  = BI_RGB; // Raw RGB
    bmi.bmiHeader.biSizeImage    = WindowWidth * WindowHeight * 1;
    bmi.bmiHeader.biClrUsed      = 16; // Colors in the palette
    bmi.bmiHeader.biClrImportant = 16; // Colors in the palette
    backbit = CreateDIBSection(0, &bmi, DIB_RGB_COLORS, (void**)&dcbits, NULL, 0);
    DeleteObject(SelectObject(backbuffer, backbit));//load the buffer into DC

    // Load private fonts
    if (SetCurrentDirectory("data\\font")){
        WIN32_FIND_DATA findData;
        for (HANDLE findFont = FindFirstFile(".\\*", &findData); findFont != INVALID_HANDLE_VALUE; )
        {
            if (!(findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)){ // Skip folders
                AddFontResourceExA(findData.cFileName, FR_PRIVATE,NULL);
            }
            if (!FindNextFile(findFont, &findData)){
                FindClose(findFont);
                break;
            }
        }
        SetCurrentDirectory("..\\..");
    }

    // Use desired font, if possible
    font = CreateFont(fontheight, fontwidth, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE,
                      ANSI_CHARSET, OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,
                      PROOF_QUALITY, FF_MODERN, typeface_c);

    SetBkMode(backbuffer, TRANSPARENT);//Transparent font backgrounds
    SelectObject(backbuffer, font);//Load our font into the DC
//    WindowCount=0;

    delete typeface_c;
    mainwin = newwin((OPTIONS["VIEWPORT_Y"] * 2 + 1),(55 + (OPTIONS["VIEWPORT_Y"] * 2 + 1)),0,0);
    return mainwin;   //create the 'stdscr' window and return its ref
}
Ejemplo n.º 15
0
//Basic Init, create the font, backbuffer, etc
WINDOW *initscr(void)
{
    _windows = new WINDOW[20];         //initialize all of our variables
    BITMAPINFO bmi;
    lastchar=-1;
    inputdelay=-1;
    std::string typeface;
    char * typeface_c;
    std::ifstream fin;
    fin.open("data\\FONTDATA");
    if (!fin.is_open()) {
        MessageBox(WindowHandle, "Failed to open FONTDATA, loading defaults.",
                   NULL, NULL);
        fontheight=16;
        fontwidth=8;
    } else {
        getline(fin, typeface);
        typeface_c= new char [typeface.size()+1];
        strcpy (typeface_c, typeface.c_str());
        fin >> fontwidth;
        fin >> fontheight;
        if ((fontwidth <= 4) || (fontheight <=4)) {
            MessageBox(WindowHandle, "Invalid font size specified!",
                       NULL, NULL);
            fontheight=16;
            fontwidth=8;
        }
    }
    halfwidth=fontwidth / 2;
    halfheight=fontheight / 2;
    WindowWidth=80*fontwidth;
    WindowHeight=25*fontheight;
    WindowX=(GetSystemMetrics(SM_CXSCREEN) / 2)-WindowWidth;    //center this
    WindowY=(GetSystemMetrics(SM_CYSCREEN) / 2)-WindowHeight;   //sucker
    WinCreate(TRUE);    //Create the actual window, register it, etc
    CheckMessages();    //Let the message queue handle setting up the window
    WindowDC = GetDC(WindowHandle);
    backbuffer = CreateCompatibleDC(WindowDC);
    ZeroMemory(&bmi, sizeof(BITMAPINFO));
    bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
    bmi.bmiHeader.biWidth = WindowWidth;
    bmi.bmiHeader.biHeight = -WindowHeight;
    bmi.bmiHeader.biPlanes = 1;
    bmi.bmiHeader.biBitCount=8;
    bmi.bmiHeader.biCompression = BI_RGB;   //store it in uncompressed bytes
    bmi.bmiHeader.biSizeImage = WindowWidth * WindowHeight * 1;
    bmi.bmiHeader.biClrUsed=16;         //the number of colors in our palette
    bmi.bmiHeader.biClrImportant=16;    //the number of colors in our palette
    backbit = CreateDIBSection(0, &bmi, DIB_RGB_COLORS, (void**)&dcbits, NULL, 0);
    DeleteObject(SelectObject(backbuffer, backbit));//load the buffer into DC

    int nResults = AddFontResourceExA("data\\termfont",FR_PRIVATE,NULL);
    if (nResults>0) {
        font = CreateFont(fontheight, fontwidth, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE,
                          ANSI_CHARSET, OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,
                          PROOF_QUALITY, FF_MODERN, typeface_c);   //Create our font

    } else {
        MessageBox(WindowHandle, "Failed to load default font, using FixedSys.",
                   NULL, NULL);
        font = CreateFont(fontheight, fontwidth, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE,
                          ANSI_CHARSET, OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,
                          PROOF_QUALITY, FF_MODERN, "FixedSys");   //Create our font
    }
    //FixedSys will be user-changable at some point in time??
    SetBkMode(backbuffer, TRANSPARENT);//Transparent font backgrounds
    SelectObject(backbuffer, font);//Load our font into the DC
    WindowCount=0;

    delete typeface_c;
    return newwin(25,80,0,0);   //create the 'stdscr' window and return its ref
};
Ejemplo n.º 16
0
//Basic Init, create the font, backbuffer, etc
WINDOW *curses_init(void)
{
   // _windows = new WINDOW[20];         //initialize all of our variables
    lastchar=-1;
    inputdelay=-1;

    std::string typeface;
    char * typeface_c;
    std::ifstream fin;
    fin.open("data\\FONTDATA");
    if (!fin.is_open()){
        MessageBox(WindowHandle, "Failed to open FONTDATA, loading defaults.", NULL, 0);
        fontheight = 16;
        fontwidth  = 8;
    } else {
        getline(fin, typeface);
        typeface_c = new char [typeface.size()+1];
        strcpy (typeface_c, typeface.c_str());
        fin >> fontwidth;
        fin >> fontheight;
        if ((fontwidth <= 4) || (fontheight <=4)){
            MessageBox(WindowHandle, "Invalid font size specified!", NULL, 0);
            fontheight = 16;
            fontwidth  = 8;
        }
    }

    halfwidth=fontwidth / 2;
    halfheight=fontheight / 2;
    WindowWidth= (55 + (OPTIONS["VIEWPORT_X"] * 2 + 1)) * fontwidth;
    WindowHeight = (OPTIONS["VIEWPORT_Y"] * 2 + 1) *fontheight;

    WinCreate();    //Create the actual window, register it, etc
    timeBeginPeriod(1); // Set Sleep resolution to 1ms
    CheckMessages();    //Let the message queue handle setting up the window

    WindowDC   = GetDC(WindowHandle);
    backbuffer = CreateCompatibleDC(WindowDC);

    BITMAPINFO bmi = {0};
    bmi.bmiHeader.biSize         = sizeof(BITMAPINFOHEADER);
    bmi.bmiHeader.biWidth        = WindowWidth;
    bmi.bmiHeader.biHeight       = -WindowHeight;
    bmi.bmiHeader.biPlanes       = 1;
    bmi.bmiHeader.biBitCount     = 8;
    bmi.bmiHeader.biCompression  = BI_RGB; // Raw RGB
    bmi.bmiHeader.biSizeImage    = WindowWidth * WindowHeight * 1;
    bmi.bmiHeader.biClrUsed      = 16; // Colors in the palette
    bmi.bmiHeader.biClrImportant = 16; // Colors in the palette
    backbit = CreateDIBSection(0, &bmi, DIB_RGB_COLORS, (void**)&dcbits, NULL, 0);
    DeleteObject(SelectObject(backbuffer, backbit));//load the buffer into DC

    int nResults = AddFontResourceExA("data\\termfont",FR_PRIVATE,NULL);
    if (nResults>0){
        font = CreateFont(fontheight, fontwidth, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE,
                          ANSI_CHARSET, OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,
                          PROOF_QUALITY, FF_MODERN, typeface_c);   //Create our font

    } else {
        MessageBox(WindowHandle, "Failed to load default font, using FixedSys.", NULL, 0);
        font = CreateFont(fontheight, fontwidth, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE,
                      ANSI_CHARSET, OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,
                      PROOF_QUALITY, FF_MODERN, "FixedSys");   //Create our font
    }
    //FixedSys will be user-changable at some point in time??
    SetBkMode(backbuffer, TRANSPARENT);//Transparent font backgrounds
    SelectObject(backbuffer, font);//Load our font into the DC
//    WindowCount=0;

    delete typeface_c;
    mainwin = newwin((OPTIONS["VIEWPORT_Y"] * 2 + 1),(55 + (OPTIONS["VIEWPORT_Y"] * 2 + 1)),0,0);
    return mainwin;   //create the 'stdscr' window and return its ref
}
Ejemplo n.º 17
0
Archivo: migd.c Proyecto: npe9/sprite
void
Migd_GatherLoad()
{
    int oldAllow;
    int	oldInput;
    int	oldForeign;
    static int iteration = 0;
    int numWritten;
    int error;
    int status;
    
    
    oldAllow = curVecPtr->allowMigration;
    oldInput = curVecPtr->noInput;
    oldForeign = curVecPtr->foreignProcs;
    if (migd_Debug > 2) {
	fprintf(stderr, "Migd_GatherLoad - time %d, oldAllow %d, oldInput %d\n",
	       time((int *) NULL), oldAllow, oldInput);
    }
    GetStats(curVecPtr->lengths, &curVecPtr->noInput,
	     &curVecPtr->foreignProcs);
    curVecPtr->timestamp = time((time_t *)0);
    ExamineLoads(curVecPtr);

    if ((oldInput > migd_Parms.noInput) &&
	(curVecPtr->noInput < migd_Parms.noInput) &&
	!ignoreInput && !migd_NeverEvict && !refuseMigration) {
	Migd_Evict(TRUE);
    }

    /*
     * Send the new load vector to the global daemon periodically,
     * or if our migration status changes, or if the number of
     * foreign processes goes from zero to non-zero or vice-versa.
     * This way the global daemon can track things like the last use
     * of a machine by a process that won't release the host when it
     * finishes.
     */
    if (iteration == 0 || (oldAllow != curVecPtr->allowMigration) ||
	(oldForeign > 0 && curVecPtr->foreignProcs == 0) ||
	(oldForeign == 0 && curVecPtr->foreignProcs > 0)) {
	if (migd_Debug > 2) {
	    fprintf(stderr,
		   "Notifying global server, iteration %d, oldAllow %d, newAllow %d, oldForeign %d, newForeign %d.\n",
		   iteration, oldAllow, curVecPtr->allowMigration,
		   oldForeign, curVecPtr->foreignProcs);
	}
	iteration = 0;

	/*
	 * Get the kernel's variable determining whether to refuse
	 * migrations.  We keep rechecking periodically in case it changes.
	 */

	status = Sys_Stats(SYS_PROC_MIGRATION, SYS_PROC_MIG_GET_STATE,
			   (Address) &migd_Parms.criteria);
	if (status != SUCCESS) {
	    SYSLOG1(LOG_ERR, "Error in Sys_Stats getting migration state: %s.\n",
		    Stat_GetMsg(status));
	    exit(Compat_MapCode(status));
	}
	ParseMigStatus();

	if (curVecPtr->lengths[1] >= 1.0)  {
	    struct timeval tv;
	    struct timeval curTime;
	    
	    /*
	     * The 5-minute load average is over 1.  This could
	     * happen if there is a long-running process but it
	     * also seems to happen without anything running.
	     * Sleep a short period of time to try to
	     * keep from being in lock-step with someone else.  There's
	     * nothing too magical about the number except that it's
	     * intended to be something that other processes are unlikely
	     * to sleep for.  
	     */
	    tv.tv_sec = 0;
	    tv.tv_usec = ((random() % 999) + 1) * 1000;
;
	    if (migd_Debug > 2) {
		if (gettimeofday(&curTime,
				 (struct timezone *) NULL) < 0) {
		    perror("Error in gettimeofday");
		    exit(1);
		}
		fprintf(stderr,
			"Sleeping %d usec to avoid lock step, time %d.%d.\n",
			tv.tv_usec, curTime.tv_sec, curTime.tv_usec);
	    }
	    if (select(0, (int *) NULL, (int *) NULL, (int *) NULL,
			  &tv) < 0) {
		if (migd_Debug > 2) {
		    perror("select");
		}
	    }
	    if (migd_Debug > 2) {
		if (gettimeofday(&curTime,
				 (struct timezone *) NULL) < 0) {
		    perror("Error in gettimeofday");
		    exit(1);
		}
		fprintf(stderr, "Time is now %d.%d.\n", curTime.tv_sec,
			curTime.tv_usec);
	    }
	}
	if (migd_Debug > 3) {
	    fprintf(stderr, "Writing vector to global daemon.\n");
	}

	/*
	 * OK, here's the tricky part.  We don't want our write to wait
	 * indefinitely, so we set an alarm.  But just waking up won't
	 * cause Fs_Write to return an error, so we have to longjmp.
	 * So we set the signal handler, set the timer, and setjmp, then
	 * after the write we reverse the process.
	 */
	if (setjmp(writejmp)) {
	    numWritten = -1;
	    errno = EIO;
	} else {
	    if ((int) signal(SIGALRM, WriteAlarm) < 0) {
		syslog(LOG_ERR, "Error setting signal handler: %s.\n",
		       strerror(errno));
		exit(1);
	    }
	    if (setitimer(ITIMER_REAL, &timeOutTimer,
			  (struct itimerval *) NULL) == -1) {
		syslog(LOG_ERR, "Error setting interval timer: %s.\n",
		       strerror(errno));
		exit(1);
	    }
	    numWritten = write(migdGlobalDesc, (char *) curVecPtr,
			       sizeof(Mig_LoadVector));
	}
	error = errno;
	if (setitimer(ITIMER_REAL, &noTimer,
		      (struct itimerval *) NULL) == -1) {
	    syslog(LOG_ERR, "Error disabling interval timer: %s.\n",
		   strerror(errno));
	    exit(1);
	}
	(void) signal(SIGALRM, SIG_IGN);
	errno = error;

	/*
	 * Now we're back to where we would be if all we'd done was
	 * write(), with errno and numWritten set to appropriate values.
	 */

	if (migd_Debug > 3) {
	    fprintf(stderr, "Write returned value %d.\n", numWritten);
	}
	if (numWritten < 0) {
	    if (migd_Debug > 0) {
		fprintf(stderr, "Error %d writing to global daemon: %s.\n",
		       error, strerror(error));
	    }
	    close(migdGlobalDesc);
	    if (migd_Quit || ContactGlobal() < 0) {
		fprintf(stderr, "Exiting.\n");
		exit(1);
	    }
	} else if (numWritten != sizeof(Mig_LoadVector)) {
	    SYSLOG2(LOG_WARNING, "short write to global daemon of %d/%d bytes.\n",
		   numWritten, sizeof(Mig_LoadVector));
	}
	iteration = 0;

	/*
	 * Check on currentInfo.state in case we have to reconnect to the
	 * global daemon or a user process reads the Mig_Info struct from
	 * us.
	 */
	if (curVecPtr->allowMigration &&
	    currentInfo.state == MIG_HOST_ACTIVE) {
	    currentInfo.state = MIG_HOST_IDLE;
	} else if (!curVecPtr->allowMigration &&
		   currentInfo.state == MIG_HOST_IDLE) {
	    currentInfo.state = refuseMigration ?
		MIG_HOST_REFUSES : MIG_HOST_ACTIVE;
	}

	if (CheckMessages() >= 0) {
	    if (migd_Debug > 0) {
		fprintf(stderr,
			"This host is being reclaimed by order of global migration daemon.\n");
	    }
	    Migd_Evict(FALSE);
	}

    }

    iteration = (iteration + 1) % writeRate;
}