1 /* Copyright (C) 2022 Wildfire Games.
2 * This file is part of 0 A.D.
4 * 0 A.D. is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
9 * 0 A.D. is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
19 * Implements the in-game console with scripting support.
22 #ifndef INCLUDED_CCONSOLE
23 #define INCLUDED_CCONSOLE
25 #include "lib/file/vfs/vfs_path.h"
26 #include "lib/input.h"
40 * - Expected to be constructed/destructed in the main thread.
41 * - InsertMessage may be called from any thread while the object is alive.
45 NONCOPYABLE(CConsole
);
53 void UpdateScreenSize(int w
, int h
);
56 void SetVisible(bool visible
);
59 * @param deltaRealTime Elapsed real time since the last frame.
61 void Update(const float deltaRealTime
);
63 void Render(CCanvas2D
& canvas
);
65 void InsertChar(const int szChar
, const wchar_t cooked
);
67 void InsertMessage(const std::string
& message
);
69 void SetBuffer(const wchar_t* szMessage
);
71 // Only returns a pointer to the buffer; copy out of here if you want to keep it.
72 const wchar_t* GetBuffer();
75 bool IsActive() const { return m_Visible
; }
78 // Lock for all state modified by InsertMessage
83 int m_FontOffset
; // distance to move up before drawing
84 size_t m_CharsPerPage
;
91 // "position" in show/hide animation, how visible the console is (0..1).
92 // allows implementing other animations than sliding, e.g. fading in/out.
95 std::deque
<std::wstring
> m_MsgHistory
; // protected by m_Mutex
96 std::deque
<std::wstring
> m_BufHistory
;
100 std::unique_ptr
<wchar_t[]> m_Buffer
;
104 VfsPath m_HistoryFile
;
105 int m_MaxHistoryLines
;
107 bool m_Visible
; // console is to be drawn
108 bool m_Toggle
; // show/hide animation is currently active
109 double m_PrevTime
; // the previous time the cursor draw state changed (used for blinking cursor)
110 bool m_CursorVisState
; // if the cursor should be drawn or not
111 bool m_QuitHotkeyWasShown
; // show console.toggle hotkey values at first time
112 double m_CursorBlinkRate
; // cursor blink rate in seconds, if greater than 0.0
114 void DrawWindow(CCanvas2D
& canvas
);
115 void DrawHistory(CTextRenderer
& textRenderer
);
116 void DrawBuffer(CTextRenderer
& textRenderer
);
117 void DrawCursor(CTextRenderer
& textRenderer
);
121 // Is beginning of Buffer?
124 bool IsEmpty() const;
126 void ProcessBuffer(const wchar_t* szLine
);
130 void ShowQuitHotkeys();
133 extern CConsole
* g_Console
;
135 extern InReaction
conInputHandler(const SDL_Event_
* ev
);
137 #endif // INCLUDED_CCONSOLE