2022-02-25 09:14:11 +01:00
|
|
|
/* Copyright (C) 2022 Wildfire Games.
|
2023-07-27 22:54:46 +02:00
|
|
|
* This file is part of 0 A.D.
|
2009-04-18 19:00:33 +02:00
|
|
|
*
|
2023-07-27 22:54:46 +02:00
|
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
2009-04-18 19:00:33 +02:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
2023-07-27 22:54:46 +02:00
|
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
2009-04-18 19:00:33 +02:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2023-07-27 22:54:46 +02:00
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
2009-04-18 19:00:33 +02:00
|
|
|
*/
|
|
|
|
|
2009-04-18 19:51:05 +02:00
|
|
|
/*
|
|
|
|
* Implements the in-game console with scripting support.
|
2007-05-07 18:33:24 +02:00
|
|
|
*/
|
2004-07-17 08:14:23 +02:00
|
|
|
|
2012-02-12 21:45:31 +01:00
|
|
|
#ifndef INCLUDED_CCONSOLE
|
|
|
|
#define INCLUDED_CCONSOLE
|
|
|
|
|
2021-05-22 01:10:43 +02:00
|
|
|
#include "lib/file/vfs/vfs_path.h"
|
|
|
|
#include "lib/input.h"
|
|
|
|
|
2004-06-02 22:40:07 +02:00
|
|
|
#include <deque>
|
2021-12-23 08:37:03 +01:00
|
|
|
#include <memory>
|
2019-06-06 21:30:48 +02:00
|
|
|
#include <mutex>
|
|
|
|
#include <string>
|
2004-06-02 22:40:07 +02:00
|
|
|
|
2021-05-30 21:10:10 +02:00
|
|
|
class CCanvas2D;
|
2012-02-12 21:45:31 +01:00
|
|
|
class CTextRenderer;
|
2004-06-02 22:40:07 +02:00
|
|
|
|
2010-10-31 23:00:28 +01:00
|
|
|
/**
|
|
|
|
* In-game console.
|
|
|
|
*
|
|
|
|
* Thread-safety:
|
|
|
|
* - Expected to be constructed/destructed in the main thread.
|
|
|
|
* - InsertMessage may be called from any thread while the object is alive.
|
|
|
|
*/
|
2004-06-02 22:40:07 +02:00
|
|
|
class CConsole
|
|
|
|
{
|
2013-05-22 23:40:56 +02:00
|
|
|
NONCOPYABLE(CConsole);
|
|
|
|
|
2008-01-07 21:03:19 +01:00
|
|
|
public:
|
|
|
|
CConsole();
|
|
|
|
~CConsole();
|
|
|
|
|
2021-05-22 01:10:43 +02:00
|
|
|
void Init();
|
|
|
|
|
2008-01-07 21:03:19 +01:00
|
|
|
void UpdateScreenSize(int w, int h);
|
|
|
|
|
|
|
|
void ToggleVisible();
|
2012-02-12 21:45:31 +01:00
|
|
|
void SetVisible(bool visible);
|
2008-01-07 21:03:19 +01:00
|
|
|
|
2012-06-06 21:37:03 +02:00
|
|
|
/**
|
|
|
|
* @param deltaRealTime Elapsed real time since the last frame.
|
|
|
|
*/
|
|
|
|
void Update(const float deltaRealTime);
|
2008-01-07 21:03:19 +01:00
|
|
|
|
2022-02-25 09:14:11 +01:00
|
|
|
void Render(CCanvas2D& canvas);
|
2008-01-07 21:03:19 +01:00
|
|
|
|
|
|
|
void InsertChar(const int szChar, const wchar_t cooked);
|
|
|
|
|
2015-02-14 02:49:34 +01:00
|
|
|
void InsertMessage(const std::string& message);
|
2008-01-07 21:03:19 +01:00
|
|
|
|
2010-03-20 23:01:39 +01:00
|
|
|
void SetBuffer(const wchar_t* szMessage);
|
2008-01-07 21:03:19 +01:00
|
|
|
|
|
|
|
// Only returns a pointer to the buffer; copy out of here if you want to keep it.
|
|
|
|
const wchar_t* GetBuffer();
|
|
|
|
void FlushBuffer();
|
|
|
|
|
2021-12-23 08:37:03 +01:00
|
|
|
bool IsActive() const { return m_Visible; }
|
2008-01-07 21:03:19 +01:00
|
|
|
|
2021-05-22 01:10:43 +02:00
|
|
|
private:
|
|
|
|
// Lock for all state modified by InsertMessage
|
|
|
|
std::mutex m_Mutex;
|
|
|
|
|
2021-12-23 08:37:03 +01:00
|
|
|
int m_FontHeight;
|
|
|
|
int m_FontWidth;
|
|
|
|
int m_FontOffset; // distance to move up before drawing
|
|
|
|
size_t m_CharsPerPage;
|
2008-01-07 21:03:19 +01:00
|
|
|
|
2021-12-23 08:37:03 +01:00
|
|
|
float m_X;
|
|
|
|
float m_Y;
|
|
|
|
float m_Height;
|
|
|
|
float m_Width;
|
2004-06-02 22:40:07 +02:00
|
|
|
|
2004-06-03 03:42:40 +02:00
|
|
|
// "position" in show/hide animation, how visible the console is (0..1).
|
|
|
|
// allows implementing other animations than sliding, e.g. fading in/out.
|
2021-12-23 08:37:03 +01:00
|
|
|
float m_VisibleFrac;
|
2016-11-23 12:18:37 +01:00
|
|
|
|
2021-12-23 08:37:03 +01:00
|
|
|
std::deque<std::wstring> m_MsgHistory; // protected by m_Mutex
|
|
|
|
std::deque<std::wstring> m_BufHistory;
|
2004-06-02 22:40:07 +02:00
|
|
|
|
2021-12-23 08:37:03 +01:00
|
|
|
int m_MsgHistPos;
|
2004-06-02 22:40:07 +02:00
|
|
|
|
2021-12-23 08:37:03 +01:00
|
|
|
std::unique_ptr<wchar_t[]> m_Buffer;
|
|
|
|
int m_BufferPos;
|
|
|
|
int m_BufferLength;
|
2004-06-02 22:40:07 +02:00
|
|
|
|
2021-12-23 08:37:03 +01:00
|
|
|
VfsPath m_HistoryFile;
|
2005-08-09 17:55:44 +02:00
|
|
|
int m_MaxHistoryLines;
|
2005-05-10 09:13:25 +02:00
|
|
|
|
2021-12-23 08:37:03 +01:00
|
|
|
bool m_Visible; // console is to be drawn
|
|
|
|
bool m_Toggle; // show/hide animation is currently active
|
|
|
|
double m_PrevTime; // the previous time the cursor draw state changed (used for blinking cursor)
|
|
|
|
bool m_CursorVisState; // if the cursor should be drawn or not
|
2021-12-07 21:09:46 +01:00
|
|
|
bool m_QuitHotkeyWasShown; // show console.toggle hotkey values at first time
|
2021-12-23 08:37:03 +01:00
|
|
|
double m_CursorBlinkRate; // cursor blink rate in seconds, if greater than 0.0
|
2004-06-02 22:40:07 +02:00
|
|
|
|
2021-05-30 21:10:10 +02:00
|
|
|
void DrawWindow(CCanvas2D& canvas);
|
2012-02-12 21:45:31 +01:00
|
|
|
void DrawHistory(CTextRenderer& textRenderer);
|
|
|
|
void DrawBuffer(CTextRenderer& textRenderer);
|
|
|
|
void DrawCursor(CTextRenderer& textRenderer);
|
2004-06-02 22:40:07 +02:00
|
|
|
|
2021-05-22 01:10:43 +02:00
|
|
|
// Is end of Buffer?
|
|
|
|
bool IsEOB() const;
|
|
|
|
// Is beginning of Buffer?
|
|
|
|
bool IsBOB() const;
|
|
|
|
bool IsFull() const;
|
|
|
|
bool IsEmpty() const;
|
2004-06-02 22:40:07 +02:00
|
|
|
|
2010-10-31 23:00:28 +01:00
|
|
|
void ProcessBuffer(const wchar_t* szLine);
|
2004-06-02 22:40:07 +02:00
|
|
|
|
2005-05-10 09:13:25 +02:00
|
|
|
void LoadHistory();
|
|
|
|
void SaveHistory();
|
2021-12-07 21:09:46 +01:00
|
|
|
void ShowQuitHotkeys();
|
2004-06-02 22:40:07 +02:00
|
|
|
};
|
|
|
|
|
2005-07-03 18:25:48 +02:00
|
|
|
extern CConsole* g_Console;
|
2004-06-11 00:24:03 +02:00
|
|
|
|
2006-08-26 23:52:18 +02:00
|
|
|
extern InReaction conInputHandler(const SDL_Event_* ev);
|
2005-08-15 01:34:37 +02:00
|
|
|
|
2021-05-22 01:10:43 +02:00
|
|
|
#endif // INCLUDED_CCONSOLE
|