2013-01-12 02:20:01 +01:00
|
|
|
/* Copyright (C) 2013 Wildfire Games.
|
2009-04-18 19:00:33 +02:00
|
|
|
* This file is part of 0 A.D.
|
|
|
|
*
|
|
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
|
|
|
* 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
|
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
|
|
2004-06-02 22:40:07 +02:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <string>
|
|
|
|
#include <deque>
|
|
|
|
#include <map>
|
|
|
|
|
2005-10-20 19:44:56 +02:00
|
|
|
#include "lib/input.h"
|
2008-01-07 21:03:19 +01:00
|
|
|
#include "lib/file/vfs/vfs_path.h"
|
2010-10-31 23:00:28 +01:00
|
|
|
#include "ps/CStr.h"
|
|
|
|
#include "ps/ThreadUtil.h"
|
2005-08-15 01:34:37 +02:00
|
|
|
|
2012-02-12 21:45:31 +01:00
|
|
|
class CShaderProgram;
|
|
|
|
typedef shared_ptr<CShaderProgram> CShaderProgramPtr;
|
|
|
|
|
|
|
|
class CTextRenderer;
|
2004-06-02 22:40:07 +02:00
|
|
|
|
2005-03-31 00:33:10 +02:00
|
|
|
#define CONSOLE_BUFFER_SIZE 1024 // for text being typed into the console
|
2004-08-14 13:40:40 +02:00
|
|
|
#define CONSOLE_MESSAGE_SIZE 1024 // for messages being printed into the console
|
2004-06-02 22:40:07 +02:00
|
|
|
|
2010-05-30 15:42:56 +02:00
|
|
|
#define CONSOLE_FONT L"mono-10"
|
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();
|
|
|
|
|
|
|
|
void SetSize(float X = 300, float Y = 0, float W = 800, float H = 600);
|
|
|
|
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
|
|
|
|
2013-01-12 02:20:01 +01:00
|
|
|
void SetCursorBlinkRate(double rate);
|
|
|
|
|
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
|
|
|
|
|
|
|
void Render();
|
|
|
|
|
2009-11-07 00:06:50 +01:00
|
|
|
void InsertMessage(const wchar_t* szMessage, ...) WPRINTF_ARGS(2);
|
2008-01-07 21:03:19 +01:00
|
|
|
void InsertChar(const int szChar, const wchar_t cooked);
|
|
|
|
|
|
|
|
void ReceivedChatMessage(const wchar_t *pSender, const wchar_t *szMessage);
|
|
|
|
|
2010-03-20 23:01:39 +01:00
|
|
|
void SetBuffer(const wchar_t* szMessage);
|
2008-01-07 21:03:19 +01:00
|
|
|
|
2012-02-12 21:45:31 +01:00
|
|
|
void UseHistoryFile(const VfsPath& filename, int historysize);
|
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();
|
|
|
|
|
|
|
|
bool IsActive() { return m_bVisible; }
|
|
|
|
|
|
|
|
int m_iFontHeight;
|
|
|
|
int m_iFontWidth;
|
|
|
|
int m_iFontOffset; // distance to move up before drawing
|
|
|
|
size_t m_charsPerPage;
|
|
|
|
|
2004-06-02 22:40:07 +02:00
|
|
|
private:
|
2010-10-31 23:00:28 +01:00
|
|
|
// Lock for all state modified by InsertMessage
|
|
|
|
CMutex m_Mutex;
|
|
|
|
|
2004-06-02 22:40:07 +02:00
|
|
|
float m_fX;
|
|
|
|
float m_fY;
|
|
|
|
|
|
|
|
float m_fHeight;
|
|
|
|
float m_fWidth;
|
|
|
|
|
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.
|
|
|
|
float m_fVisibleFrac;
|
2006-07-06 05:17:44 +02:00
|
|
|
|
2010-10-31 23:00:28 +01:00
|
|
|
std::deque<std::wstring> m_deqMsgHistory; // protected by m_Mutex
|
2004-06-16 17:42:48 +02:00
|
|
|
std::deque<std::wstring> m_deqBufHistory;
|
2004-06-02 22:40:07 +02:00
|
|
|
|
|
|
|
int m_iMsgHistPos;
|
|
|
|
|
2010-10-31 23:00:28 +01:00
|
|
|
wchar_t* m_szBuffer;
|
2004-06-02 22:40:07 +02:00
|
|
|
int m_iBufferPos;
|
|
|
|
int m_iBufferLength;
|
|
|
|
|
2008-01-07 21:03:19 +01:00
|
|
|
VfsPath m_sHistoryFile;
|
2005-08-09 17:55:44 +02:00
|
|
|
int m_MaxHistoryLines;
|
2005-05-10 09:13:25 +02:00
|
|
|
|
2010-10-31 23:00:28 +01:00
|
|
|
bool m_bFocus;
|
2004-06-03 03:42:40 +02:00
|
|
|
bool m_bVisible; // console is to be drawn
|
|
|
|
bool m_bToggle; // show/hide animation is currently active
|
2013-01-12 02:20:01 +01:00
|
|
|
double m_prevTime; // the previous time the cursor draw state changed (used for blinking cursor)
|
|
|
|
bool m_bCursorVisState; // if the cursor should be drawn or not
|
|
|
|
double m_cursorBlinkRate; // cursor blink rate in seconds, if greater than 0.0
|
2004-06-02 22:40:07 +02:00
|
|
|
|
had to remove uint and ulong from lib/types.h due to conflict with other library.
this snowballed into a massive search+destroy of the hodgepodge of
mostly equivalent types we had in use (int, uint, unsigned, unsigned
int, i32, u32, ulong, uintN).
it is more efficient to use 64-bit types in 64-bit mode, so the
preferred default is size_t (for anything remotely resembling a size or
index). tile coordinates are ssize_t to allow more efficient conversion
to/from floating point. flags are int because we almost never need more
than 15 distinct bits, bit test/set is not slower and int is fastest to
type. finally, some data that is pretty much directly passed to OpenGL
is now typed accordingly.
after several hours, the code now requires fewer casts and less
guesswork.
other changes:
- unit and player IDs now have an "invalid id" constant in the
respective class to avoid casting and -1
- fix some endian/64-bit bugs in the map (un)packing. added a
convenience function to write/read a size_t.
- ia32: change CPUID interface to allow passing in ecx (required for
cache topology detection, which I need at work). remove some unneeded
functions from asm, replace with intrinsics where possible.
This was SVN commit r5942.
2008-05-11 20:48:32 +02:00
|
|
|
void ToLower(wchar_t* szMessage, size_t iSize = 0);
|
|
|
|
void Trim(wchar_t* szMessage, const wchar_t cChar = 32, size_t iSize = 0);
|
2004-06-02 22:40:07 +02:00
|
|
|
|
2012-02-12 21:45:31 +01:00
|
|
|
void DrawWindow(CShaderProgramPtr& shader);
|
|
|
|
void DrawHistory(CTextRenderer& textRenderer);
|
|
|
|
void DrawBuffer(CTextRenderer& textRenderer);
|
|
|
|
void DrawCursor(CTextRenderer& textRenderer);
|
2004-06-02 22:40:07 +02:00
|
|
|
|
2010-10-31 23:00:28 +01:00
|
|
|
bool IsEOB() { return (m_iBufferPos == m_iBufferLength); } // Is end of Buffer?
|
|
|
|
bool IsBOB() { return (m_iBufferPos == 0); } // Is beginning of Buffer?
|
|
|
|
bool IsFull() { return (m_iBufferLength == CONSOLE_BUFFER_SIZE); }
|
|
|
|
bool IsEmpty() { return (m_iBufferLength == 0); }
|
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
|
|
|
|
2010-10-31 23:00:28 +01:00
|
|
|
// Insert message without printf-style formatting, and without length limits
|
2006-09-02 23:20:25 +02:00
|
|
|
void InsertMessageRaw(const CStrW& message);
|
|
|
|
|
2005-05-10 09:13:25 +02:00
|
|
|
void LoadHistory();
|
|
|
|
void SaveHistory();
|
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
|
|
|
|
2005-07-03 18:25:48 +02:00
|
|
|
#endif
|