WriterComponent::~THIS()
{
    COMP_NAMEtoUTF16

    console_out(TEXT("%s::dtor begin"), name);

    m_state = STATE::UNKNOWN;
    {
        if ( m_property )
        {
            m_property->Release();
            m_property = nullptr;
        }
        if ( m_owner )
        {
            console_out(TEXT("%s::ReleaseOwner begin"), name);
            {
                m_owner->Release();
                m_owner = nullptr;
            }
            console_out(TEXT("%s::ReleaseOwner end"), name);
        }
    }
    m_state = STATE::IDLE;

    console_out(TEXT("%s::dtor end"), name);
}
Example #2
0
    void SetFPS(uint16_t numerator = 1, uint16_t denominator = 1000)
    {
        fps_numerator   = (numerator > 0) ? numerator : 1;
        fps_denominator = denominator;

        console_out(TEXT("Target FPS: %f"), fps_numerator * 1000.0L / fps_denominator);
        console_out(TEXT("Time Interval: %fms"), 1.0L * fps_denominator / fps_numerator);
    }
Example #3
0
UWnd::UWnd(LPCTSTR lpszClassName)
{
    console_out(TEXT("UWnd::ctor() begin"));

    m_classname = lpszClassName;

    this->Register();

    console_out(TEXT("UWnd::ctor() end"));
}
Example #4
0
HRESULT __stdcall UWnd::ToggleFullScreen()
{
    console_out(TEXT("UWnd::ToggleFullScreen() begin"));

    m_is_fullscreen = ! m_is_fullscreen;
    console_out(TEXT("ToggleFullScreen: %s"), m_is_fullscreen ? TEXT("true") : TEXT("false"));

    MonitorUnderCursor moniter;

    HRESULT hr;
    if ( m_is_fullscreen )
    {
        m_style_old = this->style();
        ::SetWindowLongPtr(m_hwnd, GWL_STYLE, (LONG_PTR)(WS_POPUP | WS_MINIMIZEBOX));

        DEVMODE dm = { };
        dm.dmSize       = sizeof(dm);
        dm.dmFields     = DM_PELSWIDTH | DM_PELSHEIGHT;
        dm.dmPelsWidth  = moniter.witdh;
        dm.dmPelsHeight = moniter.height;

        ::SetWindowPos
        (
            m_hwnd, nullptr,
            moniter.x, moniter.y, moniter.witdh, moniter.height,
            SWP_NOZORDER | SWP_FRAMECHANGED | SWP_SHOWWINDOW
        );

        hr =  S_OK;
    }
    else
    {
        ::SetWindowLongPtr(m_hwnd, GWL_STYLE, (LONG_PTR)m_style_old);

        ::SetWindowPos
        (
            m_hwnd, nullptr,
            m_win_rect.left,
            m_win_rect.top,
            m_win_rect.right - m_win_rect.left,
            m_win_rect.bottom - m_win_rect.top,
            SWP_NOZORDER | SWP_FRAMECHANGED | SWP_SHOWWINDOW
        );

        hr =  S_FALSE;
    }

    console_out(TEXT("UWnd::ToggleFullScreen() end"));

    return hr;
}
Example #5
0
LRESULT __stdcall UWnd::WndProc(HWND hwnd, UINT uMsg, WPARAM wp, LPARAM lp)
{
    if ( uMsg == WM_DESTROY )
    {
        console_out(TEXT("UWnd::WndProc( WM_DESTROY ) begin"));
        {
            console_out(TEXT("PostQuitMessage(0)"));
            ::PostQuitMessage(0);
        }
        console_out(TEXT("UWnd::WndProc( WM_DESTROY ) end"));
    }

    return ::DefWindowProc(hwnd, uMsg, wp, lp);
}
Example #6
0
UWnd::~UWnd()
{
    console_out(TEXT("UWnd::dtor() begin"));

    if ( nullptr == m_hwnd )
    {
        console_out(TEXT("Already moved"));
        console_out(TEXT("UWnd::dtor() end"));
        return;
    }

    this->Destroy();

    console_out(TEXT("UWnd::dtor() end"));
}
Example #7
0
extern "C" HRESULT __stdcall Notify(U8CSTR msg, IData* data)
{
    console_out(TEXT("%s::Notify() begin"), NAME);

    thread_local size_t count_handled = 0;

    // デバッグ情報の表示
    console_outA("msg: %s", (char*)msg);
    console_outA("data: 0x%x", data);

    // 文字列比較のため msg を std::u8string に変換
    const auto msg_string = std::u8string(msg);

    // ...

    // メッセージチェーンに処理を投げる
    {
        SRWLock::ReadLock lock(lock_holder);

        const auto range = msg_map.equal_range(std::move(msg_string));
        const auto end = range.second;
        for ( auto it = range.first; it != end; ++it )
        {
            const auto listener = it->second;
            if ( nullptr == listener )
            {
                continue;
            }

            const auto hr = listener(msg, data);
            if ( SUCCEEDED(hr) )
            {
                ++count_handled;
            }
        }
    }

    // ...

    if ( 0 == count_handled )
    {
        console_out(TEXT("The message was handled by no listener"));
    }

    console_out(TEXT("%s::Notify() end"), NAME);

    return count_handled ? S_OK : S_FALSE;
}
Example #8
0
/*
 * Log task
 */
LOCAL void log_task( INT logtask_port )
{
	static B	logtask_buf[MBF_LOG_MAXMSZ+1];
	INT		msgsz;
	ER		ercd;

	logtask_alive = 1;
	log_msg_maxmsz = MBF_LOG_MAXMSZ;

	for ( ;; ) {
		ercd = tk_rcv_mbf(log_mbfid, logtask_buf, TMO_FEVR);
		if ( ercd < E_OK ) {
			break;
		}
		msgsz = ercd;
		logtask_buf[msgsz++] = '\n';

		ercd = console_out(logtask_port, logtask_buf, (UW)msgsz);
		if ( ercd < E_OK ) {
			sys_write(logtask_buf, msgsz);
		}
	}

	logtask_alive = 0;
	tk_exd_tsk();
}
Example #9
0
/*  update_frame
 *  Draw interface for a given frame
 */
void update_frame() {
  if (game_menu == 1) { draw_menu(); }
  else {
    // Regular game
    if ((game_mode == 0) && (game_paused == 0)) {
      paddle(PADDLE_1_XOFF,p1_h,p1_c);
      paddle(PADDLE_2_XOFF,p2_h,p2_c);
	  	ball(ball_x, ball_y, C_WHITE);

		  char* hw = "Score: ";
		  int x = 10;
		  while (*hw) {
				write_char(x, 2, *hw);
				x++;
				hw++;
		  }
	  	write_char(x, 2, '0' + p1_score);
		  hw = "Score: ";
		  x = 60;
		  while (*hw) {
				write_char(x, 2, *hw);
				x++;
				hw++;
		  }
	  	write_char(x, 2, '0' + p2_score);
    }
    // Paused game
    if (game_paused == 1) {
			unsigned char txt3[] = {'P','A','U','S','E','D','\n','\0'};
			console_out(txt3);
      fill_screen(C_RED);
		  char* hw = "GAME PAUSED";
	  	int x = 10;
		  while (*hw) {
				write_char(x, 2, *hw);
				x++;
				hw++;
		   }
    }
    // Different mode, not implemented
    if (game_mode != 0) {
			unsigned char txt4[] = {'U','N','K','N','O','W','N','\n','\0'};
			console_out(txt4);
      fill_screen(C_DBLUE);
    }
  }
}
Example #10
0
void __stdcall UWnd::AdjustRect(INT32& w, INT32& h) const
{
    console_out(TEXT("UWnd::AdjustRect begin"));
    console_out(TEXT("(w, h) = (%d, %d)"), w, h);

    RECT rc = { 0, 0, w, h };
    const BOOL hasMenu = ::GetMenu(m_hwnd) ? TRUE : FALSE;
    const auto style   = this->style();
    const auto styleEx = this->styleEx();

    ::AdjustWindowRectEx(&rc, style, hasMenu, styleEx);
    w = rc.right  - rc.left;
    h = rc.bottom - rc.top;

    console_out(TEXT("(w, h) = (%d, %d)"), w, h);
    console_out(TEXT("UWnd::AdjustRect end"));
}
Example #11
0
UWnd::UWnd(UWnd&& rhs)
{
    console_out(TEXT("UWnd::ctor(move) begin"));

    m_x             = rhs.m_x;
    m_y             = rhs.m_y;
    m_w             = rhs.m_w;
    m_h             = rhs.m_h;
    m_hwnd          = rhs.m_hwnd;
    m_classname     = rhs.m_classname;
    m_is_fullscreen = rhs.m_is_fullscreen;
    m_win_rect      = rhs.m_win_rect;

    rhs.m_hwnd = nullptr;

    console_out(TEXT("UWnd::ctor(move) end"));
}
Example #12
0
int uimon_out(const char *buffer)
{
  int rc = 0;

  if (console_log != NULL) {
    rc = console_out(console_log, buffer);
  }
  return rc;
}
Example #13
0
HRESULT __stdcall UWnd::Create
(
    LPCTSTR lpWindowName,
    DWORD   style, 
    DWORD   styleEx,
    HWND    hwndParent,
    HMENU   hMenu
)
{
    console_out(TEXT("UWnd::Create(\"%s\") begin"), m_classname);

    // 二重生成防止!
    if ( m_hwnd )
    {
        console_out(TEXT("Already created"));
        console_out(TEXT("UWnd::Create(%s) end"), m_classname);
        return S_FALSE;
    }

    // 親ウィンドウを持つ場合はウィンドウスタイルにWS_CHILDを追加
    style |= hwndParent ? WS_CHILD : 0;

    // ウィンドウを生成 … UWnd::StaticWndProc() 内で m_hwnd を格納している
    ::CreateWindowEx
    (
        styleEx, m_classname, lpWindowName, style,
        m_x, m_y, m_w, m_h,
        hwndParent, hMenu, ::GetModuleHandle(nullptr), (LPVOID)this
    );
    if ( nullptr == m_hwnd )
    {
        // エラーメッセージの表示
        ShowLastError(m_classname);
    }
    else
    {
        ::UpdateWindow(m_hwnd);
    }

    console_out(TEXT("UWnd::Create(\"%s\") end"), m_classname);

    return m_hwnd ? S_OK : E_FAIL;
}
Example #14
0
    void Reset()
    {
        ::QueryPerformanceFrequency((LARGE_INTEGER*)&frequency);
        ::QueryPerformanceCounter((LARGE_INTEGER*)&start_time);

        next_time   = 0;
        frame_count = 0;

        console_out(TEXT("PerformanceFrequency: %d"), frequency);
    }
ULONG __stdcall WriterComponent::AddRef()
{
    COMP_NAMEtoUTF16

    LONG cRef = ::InterlockedIncrement(&m_cRef);

    console_out(TEXT("%s::AddRef(): %d -> %d"), name, cRef - 1, cRef);

    return static_cast<ULONG>(cRef);
}
Example #16
0
HRESULT __stdcall UWnd::Destroy()
{
    console_out(TEXT("UWnd::Destroy() begin"));

    if ( ::IsWindow(m_hwnd) == FALSE )
    {
        console_out(TEXT("Already destroyed"));
        console_out(TEXT("UWnd::Destroy() end"));
        m_hwnd = nullptr;
        return S_FALSE;
    }

    ::DestroyWindow(m_hwnd);
    m_hwnd = nullptr;

    console_out(TEXT("UWnd::Destroy() end"));

    return S_OK;
}
Example #17
0
int uimon_out(const char *buffer)
{
    int   rc = 0;

    if (console_log)
    {
        rc = console_out(console_log, "%s", buffer);
    }
    return rc;
}
Example #18
0
UWnd& UWnd::operator =(UWnd&& rhs)
{
    console_out(TEXT("UWnd::operator =(move) begin"));

    m_x             = rhs.m_x;
    m_y             = rhs.m_y;
    m_w             = rhs.m_w;
    m_h             = rhs.m_h;
    m_hwnd          = rhs.m_hwnd;
    m_classname     = rhs.m_classname;
    m_is_fullscreen = rhs.m_is_fullscreen;
    m_win_rect      = rhs.m_win_rect;

    rhs.m_hwnd = nullptr;

    console_out(TEXT("UWnd::operator =(move) end"));

    return *this;
}
Example #19
0
void mon_set_command(console_t *console_log, char *command,
                     void (*pAfter)(void))
{
    pchCommandLine = command;

    if (console_log)
        console_out(console_log, "%s\n", command);

    if (pAfter)
        (*pAfter)();
}
WriterComponent::THIS(IUnknown* pUnkOuter)
{
    COMP_NAMEtoUTF16

    console_out(TEXT("%s::ctor begin"), name);

    if ( pUnkOuter )
    {
        console_out(TEXT("%s::GetOwnerInterface begin"), name);
        pUnkOuter->QueryInterface
        (
            IID_IComponent, (void**)&m_owner
        );
        console_out(TEXT("%s::GetOwnerInterface end"), name);
    }

    this->AddRef();

    console_out(TEXT("%s::ctor end"), name);
}
Example #21
0
HRESULT __stdcall UWnd::ToCenter()
{
    console_out(TEXT("UWnd::ToCenter() begin"));

    if ( this->parent() )
    {
        console_out(TEXT("This window has parent ... operation canceled"));
        console_out(TEXT("UWnd::ToCenter() end"));
        return S_FALSE;
    }

    MonitorUnderCursor moniter;
    const auto x = (moniter.witdh  - m_w) / 2 + moniter.x;
    const auto y = (moniter.height - m_h) / 2 + moniter.y;

    const auto result = this->Move(x, y);

    console_out(TEXT("UWnd::ToCenter() end"));

    return result;
}
HRESULT __stdcall WriterComponent::QueryInterface
(
    REFIID riid, void** ppvObject
)
{
    COMP_NAMEtoUTF16

    console_out(TEXT("%s::QueryInterface() begin"), name);

    if ( nullptr == ppvObject )
    {
        return E_POINTER;
    }

    *ppvObject = nullptr;

    if ( IsEqualIID(riid, IID_IUnknown) )
    {
        console_out(TEXT("IID_IUnknown"));
        *ppvObject = static_cast<IUnknown*>(this);
    }
    else if ( IsEqualIID(riid, IID_IComponent) )
    {
        console_out(TEXT("IID_IComponent"));
        *ppvObject = static_cast<IComponent*>(this);
    }
    else if ( IsEqualIID(riid, IID_IIOComponent) )
    {
        console_out(TEXT("IID_IIOComponent"));
        *ppvObject = static_cast<IIOComponent*>(this);
    }
    else if ( IsEqualIID(riid, IID_IWriterComponent) )
    {
        console_out(TEXT("IID_IWriterComponent"));
        *ppvObject = static_cast<IWriterComponent*>(this);
    }
    else
    {
        console_out(TEXT("No such an interface"));
        console_out(TEXT("%s::QueryInterface() end"), name);
        return E_NOINTERFACE;
    }

    this->AddRef();

    console_out(TEXT("%s::QueryInterface() end"), name);

    return S_OK;
}
Example #23
0
    MonitorUnderCursor()
    {
        console_out(TEXT("Checking which monitor is under the cursor begin"));

        POINT pt;
        ::GetCursorPos(&pt);
        const auto hMonitor = ::MonitorFromPoint(pt, MONITOR_DEFAULTTONEAREST);

        MONITORINFOEX miex = { };
        miex.cbSize = sizeof(miex);
        ::GetMonitorInfo(hMonitor, &miex);
        ::CopyMemory(name, miex.szDevice, 32 * sizeof(WCHAR));

        x      = miex.rcMonitor.left;
        y      = miex.rcMonitor.top;
        witdh  = miex.rcMonitor.right  - miex.rcMonitor.left;
        height = miex.rcMonitor.bottom - miex.rcMonitor.top;

        console_out(TEXT("%s: (X, Y) = (%d, %d)"), name, x, y);
        console_out(TEXT("%s: (Witdh, Height) = (%d, %d)"), name, witdh, height);

        console_out(TEXT("Checking which monitor is under the cursor end"));
    }
Example #24
0
/*  first_draw
 *  Draw interface for the first frame
 */
void first_draw() {
  if (game_menu == 1) { draw_menu(); }
  else {
    // Regular game
    if ((game_mode == 0) && (game_paused == 0)) {
	  	unsigned char txt2[] = {'D','r','a','w',' ','g','a','m','e','\n','\0'};
	  	console_out(txt2);
      fill_screen(C_BLACK);
	  	clear_text();
      subset(4, C_GREEN);
      meta_bar(C_BLACK);
      border(8,24,2,C_WHITE);
      paddle(PADDLE_1_XOFF,p1_h,p1_c);
      paddle(PADDLE_2_XOFF,p2_h,p2_c);
    }
    // Paused game
    if (game_paused == 1) {
			unsigned char txt3[] = {'P','A','U','S','E','D','\n','\0'};
			console_out(txt3);
      fill_screen(C_RED);
		  char* hw = "GAME PAUSED";
			int x = 10;
			while (*hw) {
				write_char(x, 2, *hw);
				x++;
				hw++;
			}
    }
    // Different mode, not implemented
    if (game_mode != 0) {
			unsigned char txt4[] = {'U','N','K','N','O','W','N','\n','\0'};
			console_out(txt4);
      fill_screen(C_DBLUE);
    }
  }
}
Example #25
0
extern "C" HRESULT __stdcall Attach(U8CSTR msg, PluginFunc listener)
{
    console_out(TEXT("%s::Attach() begin"), NAME);

    if ( nullptr == listener )
    {
        console_out(TEXT("listener is null"));
        console_out(TEXT("%s::Attach() end"), NAME);
        return E_POINTER;
    }

    // デバッグ情報の表示
    console_outA("msg: %s", (char*)msg);
    console_outA("listener: 0x%x", listener);

    // 文字列比較のため msg を std::u8string に変換
    const auto msg_string = std::u8string(msg);

    // 重複チェック
    {
        SRWLock::ReadLock lock(lock_holder);

        const auto range = msg_map.equal_range(std::move(msg_string));
        const auto end = range.second;
        for ( auto it = range.first; it != end; ++it )
        {
            if ( it->second == listener )
            {
                console_out(TEXT("Already attached"));
                console_out(TEXT("%s::Attach() end"), NAME);
                return S_FALSE;
            }
        }
    }

    // メッセージマップに登録
    {
        SRWLock::WriteLock lock(lock_holder);

        msg_map.emplace(msg, listener);
    }

    console_out(TEXT("Attachehed"));
    console_out(TEXT("%s::Attach() end"), NAME);

    return S_OK;
}
Example #26
0
extern "C" HRESULT __stdcall Detach(U8CSTR msg, PluginFunc listener)
{
    console_out(TEXT("%s::Detach() begin"), NAME);

    if ( nullptr == listener )
    {
        console_out(TEXT("listener is null"));
        console_out(TEXT("%s::Detach() end"), NAME);
        return E_POINTER;
    }

    // デバッグ情報の表示
    console_outA("msg: %s", (char*)msg);
    console_outA("listener: 0x%x", listener);

    // 文字列比較のため msg を std::u8string に変換
    const auto msg_string = std::u8string(msg);

    HRESULT hr = S_FALSE;

    // 解除対象をさがす
    {
        SRWLock::WriteLock lock(lock_holder);

        const auto range = msg_map.equal_range(std::move(msg_string));
        const auto end = range.second;
        for ( auto it = range.first; it != end; ++it )
        {
            if ( it->second == listener )
            {
                // メッセージマップから登録解除
                msg_map.erase(it);

                console_out(TEXT("Detachehed"));
                console_out(TEXT("%s::Detach() end"), NAME);
                return S_OK;
            }
        }
    }

    console_out(TEXT("Not been attached"));
    console_out(TEXT("%s::Detach() end"), NAME);

    return hr;
}
Example #27
0
char *console_in(console_t *log, const char *prompt)
{
    char *p = (char *)lib_malloc(1024);

    console_out(log, "%s", prompt);

    fflush(mon_output);
    fgets(p, 1024, mon_input);

    /* Remove trailing newlines.  */
    {
        int len;

        for (len = strlen(p);
             len > 0 && (p[len - 1] == '\r' || p[len - 1] == '\n');
             len--)
            p[len - 1] = '\0';
    }

    return p;
}
Example #28
0
static char *readline(const char *prompt)
{
    char *p = lib_malloc(1024);

    console_out(NULL, "%s", prompt);

    fflush(mon_output);
    if (fgets(p, 1024, mon_input) == NULL) {
        /* FIXME: handle error */
    }

    /* Remove trailing newlines.  */
    {
        int len;

        for (len = strlen(p); len > 0 && (p[len - 1] == '\r' || p[len - 1] == '\n'); len--) {
            p[len - 1] = '\0';
        }
    }

    return p;
}
Example #29
0
static void draw_current_input( console_private_t *pcp )
{
    int xPos = pcp->xPos;
    int yPos = pcp->yPos;

    if (!pcp->yPosInputLineStartValid) {
        pcp->xPosInputLineStart = pcp->xPos;
        pcp->yPosInputLineStart = pcp->yPos;
        pcp->cntInputBuffer = 0;
    }

    /* go to where the input line begins */
    pcp->xPos = pcp->xPosInputLineStart;
    pcp->yPos = pcp->yPosInputLineStart;

    /* set zero at end of input buffer */
    pcp->achInputBuffer[pcp->cntInputBuffer] = 0;

    /* initialize to find out if the output was scrolled up */
    pcp->scroll_up = 0;

    cursor(pcp, CS_SUSPEND);

    console_out(pcp->pConsole, "%s", pcp->achInputBuffer);

    /* output a blank to delete a possibly character after the
       input (needed for outputting after backspace or delete
    */
    console_out_character(pcp, ' ');

    /* restore cursor position */
    pcp->xPos = xPos;
    pcp->yPos = yPos - pcp->scroll_up;

    pcp->yPosInputLineStart -= pcp->scroll_up;

    cursor(pcp, CS_RESUME);
}
Example #30
0
    void SetNextTime()
    {
        // 64bit 環境であれば、frame_count は 240fps の場合で
        // 約 2,435,643,939 年後に オーバーフローします。
        // (32bit 環境だと 約 207 日後。)
        if ( frame_count > (1 << (32 - 1)) )
        {
            console_out(TEXT("念のためオーバーフロー防止"));
            this->Reset();
        }
        //console_out(TEXT("frame_count: %u"), frame_count);

        int64_t present_time;
        ::QueryPerformanceCounter((LARGE_INTEGER*)&present_time);

        while ( next_time < present_time )
        {
            ++frame_count;
            next_time = start_time +
                        (frame_count * frequency * fps_denominator) /
                        (fps_numerator * 1000);
        }
        //console_out(TEXT("next_time: %d, present_time: %d"), next_time, present_time);
    }