2010-11-20 10:37:14 +00:00
|
|
|
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
|
|
|
|
/* If you are missing that file, acquire a complete release at teeworlds.com. */
|
2010-05-29 07:25:38 +00:00
|
|
|
#ifndef ENGINE_DEMO_H
|
|
|
|
#define ENGINE_DEMO_H
|
|
|
|
|
2020-09-26 19:41:58 +00:00
|
|
|
#include "kernel.h"
|
2019-10-14 00:27:08 +00:00
|
|
|
#include <base/hash.h>
|
2020-06-18 16:29:27 +00:00
|
|
|
#include <engine/map.h>
|
2019-12-17 14:44:54 +00:00
|
|
|
#include <engine/shared/uuid_manager.h>
|
2010-05-29 07:25:38 +00:00
|
|
|
|
2012-01-10 22:13:19 +00:00
|
|
|
enum
|
|
|
|
{
|
2020-09-26 19:41:58 +00:00
|
|
|
MAX_TIMELINE_MARKERS = 64
|
2012-01-10 22:13:19 +00:00
|
|
|
};
|
|
|
|
|
2023-09-23 19:06:39 +00:00
|
|
|
static const unsigned char gs_aHeaderMarker[7] = {'T', 'W', 'D', 'E', 'M', 'O', 0};
|
|
|
|
|
2022-03-21 08:01:56 +00:00
|
|
|
constexpr int g_DemoSpeeds = 22;
|
|
|
|
extern const double g_aSpeeds[g_DemoSpeeds];
|
2016-10-28 07:31:22 +00:00
|
|
|
|
2017-02-28 09:08:14 +00:00
|
|
|
typedef bool (*DEMOFUNC_FILTER)(const void *pData, int DataSize, void *pUser);
|
|
|
|
|
2019-12-17 14:44:54 +00:00
|
|
|
// TODO: Properly extend demo format using uuids
|
2020-09-25 16:11:59 +00:00
|
|
|
// "6be6da4a-cebd-380c-9b5b-1289c842d780"
|
|
|
|
// "demoitem-sha256@ddnet.tw"
|
2022-03-21 08:01:56 +00:00
|
|
|
extern const CUuid SHA256_EXTENSION;
|
2019-12-17 14:44:54 +00:00
|
|
|
|
2011-03-13 09:41:10 +00:00
|
|
|
struct CDemoHeader
|
|
|
|
{
|
|
|
|
unsigned char m_aMarker[7];
|
|
|
|
unsigned char m_Version;
|
|
|
|
char m_aNetversion[64];
|
2020-06-19 08:41:56 +00:00
|
|
|
char m_aMapName[64];
|
2023-02-04 00:22:49 +00:00
|
|
|
unsigned char m_aMapSize[sizeof(int32_t)];
|
|
|
|
unsigned char m_aMapCrc[sizeof(int32_t)];
|
2011-03-13 09:41:10 +00:00
|
|
|
char m_aType[8];
|
2023-02-04 00:22:49 +00:00
|
|
|
unsigned char m_aLength[sizeof(int32_t)];
|
2011-03-13 09:41:10 +00:00
|
|
|
char m_aTimestamp[20];
|
2023-09-23 19:06:39 +00:00
|
|
|
|
|
|
|
bool Valid() const
|
|
|
|
{
|
|
|
|
// Check marker and ensure that strings are zero-terminated and valid UTF-8.
|
|
|
|
return mem_comp(m_aMarker, gs_aHeaderMarker, sizeof(gs_aHeaderMarker)) == 0 &&
|
|
|
|
mem_has_null(m_aNetversion, sizeof(m_aNetversion)) && str_utf8_check(m_aNetversion) &&
|
|
|
|
mem_has_null(m_aMapName, sizeof(m_aMapName)) && str_utf8_check(m_aMapName) &&
|
|
|
|
mem_has_null(m_aType, sizeof(m_aType)) && str_utf8_check(m_aType) &&
|
|
|
|
mem_has_null(m_aTimestamp, sizeof(m_aTimestamp)) && str_utf8_check(m_aTimestamp);
|
|
|
|
}
|
2013-02-25 23:00:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct CTimelineMarkers
|
|
|
|
{
|
2023-02-04 00:22:49 +00:00
|
|
|
unsigned char m_aNumTimelineMarkers[sizeof(int32_t)];
|
|
|
|
unsigned char m_aTimelineMarkers[MAX_TIMELINE_MARKERS][sizeof(int32_t)];
|
2011-03-13 09:41:10 +00:00
|
|
|
};
|
|
|
|
|
2019-10-14 00:27:08 +00:00
|
|
|
struct CMapInfo
|
|
|
|
{
|
2020-06-18 16:29:27 +00:00
|
|
|
char m_aName[MAX_MAP_LENGTH];
|
2019-10-14 00:27:08 +00:00
|
|
|
SHA256_DIGEST m_Sha256;
|
2023-10-18 19:21:26 +00:00
|
|
|
unsigned m_Crc;
|
|
|
|
unsigned m_Size;
|
2019-10-14 00:27:08 +00:00
|
|
|
};
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
class IDemoPlayer : public IInterface
|
|
|
|
{
|
2023-11-28 20:46:03 +00:00
|
|
|
MACRO_INTERFACE("demoplayer")
|
2010-05-29 07:25:38 +00:00
|
|
|
public:
|
|
|
|
class CInfo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
bool m_Paused;
|
|
|
|
float m_Speed;
|
|
|
|
|
|
|
|
int m_FirstTick;
|
|
|
|
int m_CurrentTick;
|
|
|
|
int m_LastTick;
|
2012-01-10 22:13:19 +00:00
|
|
|
|
|
|
|
int m_NumTimelineMarkers;
|
|
|
|
int m_aTimelineMarkers[MAX_TIMELINE_MARKERS];
|
2010-05-29 07:25:38 +00:00
|
|
|
};
|
|
|
|
|
2022-08-28 15:52:49 +00:00
|
|
|
enum ETickOffset
|
|
|
|
{
|
2022-12-30 19:24:11 +00:00
|
|
|
TICK_CURRENT, // update the current tick again
|
|
|
|
TICK_PREVIOUS, // go to the previous tick
|
|
|
|
TICK_NEXT, // go to the next tick
|
2022-08-28 15:52:49 +00:00
|
|
|
};
|
|
|
|
|
2023-10-10 19:44:32 +00:00
|
|
|
virtual ~IDemoPlayer() {}
|
2010-05-29 07:25:38 +00:00
|
|
|
virtual void SetSpeed(float Speed) = 0;
|
2023-07-08 00:45:39 +00:00
|
|
|
virtual void SetSpeedIndex(int SpeedIndex) = 0;
|
|
|
|
virtual void AdjustSpeedIndex(int Offset) = 0;
|
2019-04-15 18:39:39 +00:00
|
|
|
virtual int SeekPercent(float Percent) = 0;
|
|
|
|
virtual int SeekTime(float Seconds) = 0;
|
2022-08-28 15:52:49 +00:00
|
|
|
virtual int SeekTick(ETickOffset TickOffset) = 0;
|
2019-04-15 18:39:39 +00:00
|
|
|
virtual int SetPos(int WantedTick) = 0;
|
2010-05-29 07:25:38 +00:00
|
|
|
virtual void Pause() = 0;
|
|
|
|
virtual void Unpause() = 0;
|
2014-04-26 19:00:14 +00:00
|
|
|
virtual bool IsPlaying() const = 0;
|
2010-05-29 07:25:38 +00:00
|
|
|
virtual const CInfo *BaseInfo() const = 0;
|
2023-10-16 19:52:56 +00:00
|
|
|
virtual void GetDemoName(char *pBuffer, size_t BufferSize) const = 0;
|
2023-10-18 19:21:26 +00:00
|
|
|
virtual bool GetDemoInfo(class IStorage *pStorage, class IConsole *pConsole, const char *pFilename, int StorageType, CDemoHeader *pDemoHeader, CTimelineMarkers *pTimelineMarkers, CMapInfo *pMapInfo, IOHANDLE *pFile = nullptr, char *pErrorMessage = nullptr, size_t ErrorMessageSize = 0) const = 0;
|
2010-05-29 07:25:38 +00:00
|
|
|
};
|
|
|
|
|
2010-08-09 12:14:15 +00:00
|
|
|
class IDemoRecorder : public IInterface
|
|
|
|
{
|
2023-11-28 20:46:03 +00:00
|
|
|
MACRO_INTERFACE("demorecorder")
|
2010-08-09 12:14:15 +00:00
|
|
|
public:
|
2023-10-10 19:44:32 +00:00
|
|
|
virtual ~IDemoRecorder() {}
|
2010-08-09 12:14:15 +00:00
|
|
|
virtual bool IsRecording() const = 0;
|
2017-07-08 11:38:27 +00:00
|
|
|
virtual int Stop() = 0;
|
2011-03-12 17:34:16 +00:00
|
|
|
virtual int Length() const = 0;
|
2019-05-24 22:24:13 +00:00
|
|
|
virtual char *GetCurrentFilename() = 0;
|
2010-08-09 12:14:15 +00:00
|
|
|
};
|
|
|
|
|
2014-08-12 14:21:06 +00:00
|
|
|
class IDemoEditor : public IInterface
|
|
|
|
{
|
2023-11-28 20:46:03 +00:00
|
|
|
MACRO_INTERFACE("demoeditor")
|
2014-08-12 14:21:06 +00:00
|
|
|
public:
|
2017-02-28 09:08:14 +00:00
|
|
|
virtual void Slice(const char *pDemo, const char *pDst, int StartTick, int EndTick, DEMOFUNC_FILTER pfnFilter, void *pUser) = 0;
|
2014-08-12 14:21:06 +00:00
|
|
|
};
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
#endif
|