2016-03-27 11:49:47 +02:00
|
|
|
/*
|
|
|
|
===========================================================================
|
|
|
|
Copyright (C) 2008 the OpenMoHAA team
|
|
|
|
|
|
|
|
This file is part of OpenMoHAA source code.
|
|
|
|
|
|
|
|
OpenMoHAA source code 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.
|
|
|
|
|
|
|
|
OpenMoHAA source code 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 OpenMoHAA source code; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
===========================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
// listener.h: Listener
|
|
|
|
|
2023-01-29 20:59:31 +01:00
|
|
|
#pragma once
|
2016-03-27 11:49:47 +02:00
|
|
|
|
|
|
|
#include "class.h"
|
2023-01-29 20:59:31 +01:00
|
|
|
#include "containerclass.h"
|
|
|
|
#include "con_arrayset.h"
|
|
|
|
#include "str.h"
|
|
|
|
#include "vector.h"
|
2016-03-27 11:49:47 +02:00
|
|
|
|
|
|
|
class Entity;
|
|
|
|
class Listener;
|
|
|
|
class ScriptClass;
|
|
|
|
class ScriptThread;
|
|
|
|
class ScriptVariable;
|
|
|
|
class ScriptVariableList;
|
|
|
|
class ScriptVM;
|
|
|
|
class SimpleEntity;
|
|
|
|
class Archiver;
|
|
|
|
class EventQueueNode;
|
|
|
|
|
|
|
|
// entity subclass
|
2023-11-16 23:11:48 +01:00
|
|
|
#define ECF_ENTITY (1 << 0)
|
|
|
|
#define ECF_ANIMATE (1 << 1)
|
|
|
|
#define ECF_SENTIENT (1 << 2)
|
|
|
|
#define ECF_PLAYER (1 << 3)
|
|
|
|
#define ECF_ACTOR (1 << 4)
|
|
|
|
#define ECF_ITEM (1 << 5)
|
|
|
|
#define ECF_INVENTORYITEM (1 << 6)
|
|
|
|
#define ECF_WEAPON (1 << 7)
|
|
|
|
#define ECF_PROJECTILE (1 << 8)
|
|
|
|
#define ECF_DOOR (1 << 9)
|
|
|
|
#define ECF_CAMERA (1 << 10)
|
|
|
|
#define ECF_VEHICLE (1 << 11)
|
|
|
|
#define ECF_VEHICLETANK (1 << 12)
|
|
|
|
#define ECF_VEHICLETURRET (1 << 13)
|
|
|
|
#define ECF_TURRET (1 << 14)
|
|
|
|
#define ECF_PATHNODE (1 << 15)
|
|
|
|
#define ECF_WAYPOINT (1 << 16)
|
|
|
|
#define ECF_TEMPWAYPOINT (1 << 17)
|
|
|
|
#define ECF_VEHICLEPOINT (1 << 18)
|
|
|
|
#define ECF_SPLINEPATH (1 << 19)
|
|
|
|
#define ECF_CRATEOBJECT (1 << 20)
|
|
|
|
#define ECF_BOT (1 << 21)
|
2016-03-27 11:49:47 +02:00
|
|
|
|
|
|
|
// Event flags
|
2023-09-17 16:26:48 +02:00
|
|
|
#define EV_CONSOLE (1 << 0) // Allow entry from console
|
|
|
|
#define EV_CHEAT (1 << 1) // Only allow entry from console if cheats are enabled
|
|
|
|
#define EV_CODEONLY (1 << 2) // Hide from eventlist
|
|
|
|
#define EV_CACHE (1 << 3) // This event is used to cache data in
|
|
|
|
#define EV_TIKIONLY (1 << 4) // This command only applies to TIKI files
|
|
|
|
#define EV_SCRIPTONLY (1 << 5) // This command only applies to SCRIPT files
|
|
|
|
#define EV_SERVERCMD (1 << 6) // Client : server command
|
|
|
|
#define EV_DEFAULT -1 // default flag
|
|
|
|
#define EV_ZERO 0
|
2016-03-27 11:49:47 +02:00
|
|
|
|
|
|
|
// Event types
|
2023-09-17 16:26:48 +02:00
|
|
|
#define EV_NORMAL 0 // Normal command
|
|
|
|
#define EV_RETURN 1 // Return as a function (local.var = local ReturnCommand)
|
|
|
|
#define EV_GETTER 2 // Return as a variable (local.var = local.listener.some_getter)
|
|
|
|
#define EV_SETTER 3 // Set as a variable (local.listener.some_setter = "value")
|
2016-03-27 11:49:47 +02:00
|
|
|
|
|
|
|
// times for posting events
|
2023-09-17 16:26:48 +02:00
|
|
|
// Even though negative times technically don't make sense, the effect is to
|
2016-03-27 11:49:47 +02:00
|
|
|
// sort events that take place at the start of a map so that they are executed
|
|
|
|
// in the proper order. For example, spawnargs must occur before any script
|
|
|
|
// commands take place, while unused entities must be removed before the spawnargs
|
|
|
|
// are parsed.
|
|
|
|
|
2023-11-03 22:07:43 +01:00
|
|
|
#define EV_REMOVE -9.0f // remove any unused entities before spawnargs are parsed
|
2024-01-24 21:51:46 +01:00
|
|
|
#define EV_LINKBEAMS -9.0f // for finding out the endpoints of beams
|
2023-09-17 16:26:48 +02:00
|
|
|
#define EV_VEHICLE -9.0f
|
|
|
|
#define EV_PRIORITY_SPAWNARG -8.0f // for priority spawn args passed in by the bsp file
|
|
|
|
#define EV_SETUP_ROPEPIECE -8.0f
|
|
|
|
#define EV_SPAWNARG -7.0f // for spawn args passed in by the bsp file
|
|
|
|
#define EV_SETUP_ROPEBASE -7.0f
|
|
|
|
#define EV_PROCESS_INIT -6.0f
|
|
|
|
#define EV_LINKDOORS -6.0f // for finding out which doors are linked together
|
|
|
|
#define EV_POSTSPAWN -5.0f // for any processing that must occur after all objects are spawned
|
|
|
|
#define EV_SPAWNENTITIES -4.0f
|
|
|
|
#define EV_PRIORITY_SPAWNACTOR -3.0f
|
|
|
|
#define EV_SPAWNACTOR -2.0f
|
2016-03-27 11:49:47 +02:00
|
|
|
|
|
|
|
// Posted Event Flags
|
2023-09-17 16:26:48 +02:00
|
|
|
#define EVENT_LEGS_ANIM (1 << 0) // this event is associated with an animation for the legs
|
|
|
|
#define EVENT_TORSO_ANIM (1 << 1) // this event is associated with an animation for the torso
|
|
|
|
#define EVENT_DIALOG_ANIM (1 << 2) // this event is associated with an animation for dialog lip syncing
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
IS_STRING,
|
|
|
|
IS_VECTOR,
|
|
|
|
IS_BOOLEAN,
|
|
|
|
IS_INTEGER,
|
|
|
|
IS_FLOAT,
|
|
|
|
IS_ENTITY,
|
|
|
|
IS_LISTENER
|
2016-03-27 11:49:47 +02:00
|
|
|
} vartype;
|
|
|
|
|
|
|
|
class EventArgDef : public Class
|
|
|
|
{
|
|
|
|
private:
|
2023-09-17 16:26:48 +02:00
|
|
|
int type;
|
|
|
|
str name;
|
|
|
|
float minRange[3];
|
|
|
|
qboolean minRangeDefault[3];
|
|
|
|
float maxRange[3];
|
|
|
|
qboolean maxRangeDefault[3];
|
|
|
|
qboolean optional;
|
2016-03-27 11:49:47 +02:00
|
|
|
|
2023-09-17 16:26:48 +02:00
|
|
|
public:
|
|
|
|
EventArgDef()
|
|
|
|
{
|
|
|
|
type = IS_INTEGER;
|
|
|
|
//name = "undefined";
|
|
|
|
optional = qfalse;
|
|
|
|
};
|
|
|
|
|
|
|
|
void Setup(const char *eventName, const char *argName, const char *argType, const char *argRange);
|
|
|
|
void PrintArgument(FILE *event_file = NULL);
|
|
|
|
void PrintRange(FILE *event_file = NULL);
|
|
|
|
int getType(void);
|
|
|
|
const char *getName(void);
|
|
|
|
qboolean isOptional(void);
|
|
|
|
|
|
|
|
float GetMinRange(int index)
|
|
|
|
{
|
|
|
|
if (index < 3) {
|
|
|
|
return minRange[index];
|
|
|
|
}
|
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
qboolean GetMinRangeDefault(int index)
|
|
|
|
{
|
|
|
|
if (index < 3) {
|
|
|
|
return minRangeDefault[index];
|
|
|
|
}
|
|
|
|
return qfalse;
|
|
|
|
}
|
|
|
|
|
|
|
|
float GetMaxRange(int index)
|
|
|
|
{
|
|
|
|
if (index < 3) {
|
|
|
|
return maxRange[index];
|
|
|
|
}
|
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
qboolean GetMaxRangeDefault(int index)
|
|
|
|
{
|
|
|
|
if (index < 3) {
|
|
|
|
return maxRangeDefault[index];
|
|
|
|
}
|
|
|
|
return qfalse;
|
|
|
|
}
|
2016-03-27 11:49:47 +02:00
|
|
|
};
|
|
|
|
|
2023-09-17 16:26:48 +02:00
|
|
|
inline int EventArgDef::getType(void)
|
2016-03-27 11:49:47 +02:00
|
|
|
{
|
2023-09-17 16:26:48 +02:00
|
|
|
return type;
|
2016-03-27 11:49:47 +02:00
|
|
|
}
|
|
|
|
|
2023-09-17 16:26:48 +02:00
|
|
|
inline const char *EventArgDef::getName(void)
|
2016-03-27 11:49:47 +02:00
|
|
|
{
|
2023-09-17 16:26:48 +02:00
|
|
|
return name.c_str();
|
2016-03-27 11:49:47 +02:00
|
|
|
}
|
|
|
|
|
2023-09-17 16:26:48 +02:00
|
|
|
inline qboolean EventArgDef::isOptional(void)
|
2016-03-27 11:49:47 +02:00
|
|
|
{
|
2023-09-17 16:26:48 +02:00
|
|
|
return optional;
|
2016-03-27 11:49:47 +02:00
|
|
|
}
|
|
|
|
|
2023-09-17 16:26:48 +02:00
|
|
|
class EventDef
|
|
|
|
{
|
2016-03-27 11:49:47 +02:00
|
|
|
public:
|
2023-09-17 16:26:48 +02:00
|
|
|
str command;
|
|
|
|
int flags;
|
|
|
|
const char *formatspec;
|
|
|
|
const char *argument_names;
|
|
|
|
const char *documentation;
|
|
|
|
uchar type;
|
|
|
|
Container<EventArgDef> *definition;
|
2016-03-27 11:49:47 +02:00
|
|
|
|
2023-09-17 16:26:48 +02:00
|
|
|
EventDef() { definition = NULL; }
|
2016-03-27 11:49:47 +02:00
|
|
|
|
2023-09-17 16:26:48 +02:00
|
|
|
void Error(const char *format, ...);
|
2016-03-27 11:49:47 +02:00
|
|
|
|
2023-09-17 16:26:48 +02:00
|
|
|
void PrintDocumentation(FILE *event_file, bool html);
|
|
|
|
void PrintEventDocumentation(FILE *event_file, bool html);
|
2016-03-27 11:49:47 +02:00
|
|
|
|
2023-09-17 16:26:48 +02:00
|
|
|
void DeleteDocumentation(void);
|
|
|
|
void SetupDocumentation(void);
|
2016-03-27 11:49:47 +02:00
|
|
|
};
|
|
|
|
|
2023-09-17 16:26:48 +02:00
|
|
|
class DataNode
|
|
|
|
{
|
2023-09-04 21:38:58 +02:00
|
|
|
public:
|
2023-09-17 16:26:48 +02:00
|
|
|
Event *ev;
|
|
|
|
const char *command;
|
|
|
|
int flags;
|
|
|
|
const char *formatspec;
|
|
|
|
const char *argument_names;
|
|
|
|
const char *documentation;
|
|
|
|
int type;
|
|
|
|
DataNode *next;
|
2023-09-04 21:38:58 +02:00
|
|
|
};
|
|
|
|
|
2023-09-17 16:26:48 +02:00
|
|
|
class command_t
|
|
|
|
{
|
2016-03-27 11:49:47 +02:00
|
|
|
public:
|
2023-09-17 16:26:48 +02:00
|
|
|
const char *command;
|
|
|
|
int flags;
|
|
|
|
byte type;
|
2016-03-27 11:49:47 +02:00
|
|
|
|
2023-09-07 18:05:49 +02:00
|
|
|
public:
|
2023-09-17 16:26:48 +02:00
|
|
|
command_t();
|
|
|
|
command_t(const char *name, byte t);
|
2023-09-07 18:05:49 +02:00
|
|
|
|
2023-09-17 16:26:48 +02:00
|
|
|
friend bool operator==(const char *name, const command_t& command);
|
|
|
|
friend bool operator==(const command_t& cmd1, const command_t& cmd2);
|
2016-03-27 11:49:47 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class Event : public Class
|
|
|
|
{
|
|
|
|
public:
|
2023-09-17 16:26:48 +02:00
|
|
|
qboolean fromScript;
|
|
|
|
short unsigned int eventnum;
|
|
|
|
short unsigned int dataSize;
|
|
|
|
short unsigned int maxDataSize;
|
|
|
|
ScriptVariable *data;
|
2016-03-27 11:49:47 +02:00
|
|
|
|
|
|
|
#ifdef _DEBUG
|
2023-09-17 16:26:48 +02:00
|
|
|
// should be used only for debugging purposes
|
|
|
|
const char *name;
|
2016-03-27 11:49:47 +02:00
|
|
|
#endif
|
|
|
|
|
2023-09-04 21:38:58 +02:00
|
|
|
private:
|
2023-09-17 16:26:48 +02:00
|
|
|
static DataNode *DataNodeList;
|
2023-09-04 21:38:58 +02:00
|
|
|
|
2016-03-27 11:49:47 +02:00
|
|
|
public:
|
2023-09-17 16:26:48 +02:00
|
|
|
CLASS_PROTOTYPE(Event);
|
2016-03-27 11:49:47 +02:00
|
|
|
|
2023-09-17 16:26:48 +02:00
|
|
|
static con_map<Event *, EventDef> eventDefList;
|
|
|
|
static con_arrayset<command_t, command_t> commandList;
|
2016-03-27 11:49:47 +02:00
|
|
|
|
2023-09-17 16:26:48 +02:00
|
|
|
static con_map<const_str, unsigned int> normalCommandList;
|
|
|
|
static con_map<const_str, unsigned int> returnCommandList;
|
|
|
|
static con_map<const_str, unsigned int> getterCommandList;
|
|
|
|
static con_map<const_str, unsigned int> setterCommandList;
|
2016-03-27 11:49:47 +02:00
|
|
|
|
2023-09-17 16:26:48 +02:00
|
|
|
static void LoadEvents(void);
|
2016-03-27 11:49:47 +02:00
|
|
|
|
2023-09-17 16:26:48 +02:00
|
|
|
static EventQueueNode EventQueue;
|
2016-03-27 11:49:47 +02:00
|
|
|
|
2023-09-17 16:26:48 +02:00
|
|
|
static int NumEventCommands();
|
2016-03-27 11:49:47 +02:00
|
|
|
|
2023-09-17 16:26:48 +02:00
|
|
|
static void ListCommands(const char *mask = NULL);
|
|
|
|
static void ListDocumentation(const char *mask, qboolean print_to_file = qfalse);
|
|
|
|
static void PendingEvents(const char *mask = NULL);
|
2016-03-27 11:49:47 +02:00
|
|
|
|
2023-09-17 16:26:48 +02:00
|
|
|
static int GetEvent(str name, uchar type = EV_NORMAL);
|
|
|
|
static int GetEventWithFlags(str name, int flags, uchar type = EV_NORMAL);
|
2016-03-27 11:49:47 +02:00
|
|
|
|
2023-09-17 16:26:48 +02:00
|
|
|
static command_t *GetEventInfo(int eventnum);
|
|
|
|
static int GetEventFlags(int eventnum);
|
|
|
|
static const char *GetEventName(int index);
|
2016-03-27 11:49:47 +02:00
|
|
|
|
2023-09-17 16:26:48 +02:00
|
|
|
static int compareEvents(const void *arg1, const void *arg2);
|
|
|
|
static void SortEventList(Container<int> *sortedList);
|
2016-03-27 11:49:47 +02:00
|
|
|
|
2023-09-17 16:26:48 +02:00
|
|
|
virtual void ErrorInternal(Listener *l, str text) const;
|
2016-03-27 11:49:47 +02:00
|
|
|
|
2024-01-24 21:51:46 +01:00
|
|
|
static bool Exists(const char *command);
|
2023-09-17 16:26:48 +02:00
|
|
|
static unsigned int FindEventNum(const char *s);
|
|
|
|
static unsigned int FindNormalEventNum(const_str s);
|
|
|
|
static unsigned int FindNormalEventNum(str s);
|
|
|
|
static unsigned int FindReturnEventNum(const_str s);
|
|
|
|
static unsigned int FindReturnEventNum(str s);
|
|
|
|
static unsigned int FindSetterEventNum(const_str s);
|
|
|
|
static unsigned int FindSetterEventNum(str s);
|
|
|
|
static unsigned int FindGetterEventNum(const_str s);
|
|
|
|
static unsigned int FindGetterEventNum(str s);
|
2016-03-27 11:49:47 +02:00
|
|
|
|
2023-09-17 16:26:48 +02:00
|
|
|
bool operator==(Event ev) { return eventnum == ev.eventnum; }
|
|
|
|
|
|
|
|
bool operator!=(Event ev) { return eventnum != ev.eventnum; }
|
2016-03-27 11:49:47 +02:00
|
|
|
|
2017-02-19 12:13:43 +01:00
|
|
|
#ifndef _DEBUG_MEM
|
2023-09-17 16:26:48 +02:00
|
|
|
void *operator new(size_t size);
|
|
|
|
void operator delete(void *ptr);
|
2017-02-19 12:13:43 +01:00
|
|
|
#endif
|
2016-03-27 11:49:47 +02:00
|
|
|
|
2023-09-07 18:21:03 +02:00
|
|
|
Event();
|
|
|
|
Event(const Event& ev);
|
2023-09-17 16:26:48 +02:00
|
|
|
Event(const Event& ev, int numArgs);
|
2023-09-07 18:21:03 +02:00
|
|
|
Event(Event&& ev);
|
|
|
|
Event(int index);
|
|
|
|
Event(int index, int numArgs);
|
2023-09-17 16:26:48 +02:00
|
|
|
Event(const char *command);
|
|
|
|
Event(const char *command, int numArgs);
|
|
|
|
Event(
|
|
|
|
const char *command,
|
|
|
|
int flags,
|
|
|
|
const char *
|
|
|
|
formatspec, // Arguments are : 'e' (Entity) 'v' (Vector) 'i' (Integer) 'f' (Float) 's' (String) 'b' (Boolean).
|
2023-09-07 18:21:03 +02:00
|
|
|
// Uppercase arguments means optional.
|
2023-09-17 16:26:48 +02:00
|
|
|
const char *argument_names,
|
|
|
|
const char *documentation,
|
|
|
|
byte type = EV_NORMAL
|
2023-09-07 18:21:03 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
Event& operator=(const Event& ev);
|
|
|
|
Event& operator=(Event&& ev);
|
2016-03-27 11:49:47 +02:00
|
|
|
|
2023-09-17 16:26:48 +02:00
|
|
|
~Event();
|
2016-03-27 11:49:47 +02:00
|
|
|
|
2023-01-29 20:59:31 +01:00
|
|
|
#if defined(ARCHIVE_SUPPORTED)
|
2023-09-17 16:26:48 +02:00
|
|
|
void Archive(Archiver& arc) override;
|
2023-01-29 20:59:31 +01:00
|
|
|
#endif
|
2016-03-27 11:49:47 +02:00
|
|
|
|
|
|
|
#ifdef _GAME_DLL
|
2023-09-17 16:26:48 +02:00
|
|
|
eventInfo_t *getInfo();
|
2016-03-27 11:49:47 +02:00
|
|
|
#else
|
2023-09-17 16:26:48 +02:00
|
|
|
EventDef *getInfo();
|
2016-03-27 11:49:47 +02:00
|
|
|
#endif
|
|
|
|
|
2023-09-17 16:26:48 +02:00
|
|
|
const char *getName() const;
|
2016-03-27 11:49:47 +02:00
|
|
|
|
2023-09-17 16:26:48 +02:00
|
|
|
void AddContainer(Container<SafePtr<Listener>> *container);
|
|
|
|
void AddEntity(Entity *ent);
|
|
|
|
void AddFloat(float number);
|
|
|
|
void AddInteger(int number);
|
|
|
|
void AddListener(Listener *listener);
|
|
|
|
void AddNil(void);
|
|
|
|
void AddConstString(const_str string);
|
|
|
|
void AddString(str string);
|
|
|
|
void AddToken(str token);
|
|
|
|
void AddTokens(int argc, const char **argv);
|
|
|
|
void AddValue(const ScriptVariable& value);
|
|
|
|
void AddVector(const Vector& vector);
|
2024-01-24 21:51:46 +01:00
|
|
|
void CopyValues(const ScriptVariable *values, size_t count);
|
2016-03-27 11:49:47 +02:00
|
|
|
|
2023-09-17 16:26:48 +02:00
|
|
|
void Clear(void);
|
2016-03-27 11:49:47 +02:00
|
|
|
|
2023-09-17 16:26:48 +02:00
|
|
|
void CheckPos(int pos);
|
2016-03-27 11:49:47 +02:00
|
|
|
|
2023-09-17 16:26:48 +02:00
|
|
|
bool GetBoolean(int pos);
|
2016-03-27 11:49:47 +02:00
|
|
|
|
2023-09-17 16:26:48 +02:00
|
|
|
const_str GetConstString(int pos);
|
2016-03-27 11:49:47 +02:00
|
|
|
|
2023-09-17 16:26:48 +02:00
|
|
|
Entity *GetEntity(int pos);
|
2016-03-27 11:49:47 +02:00
|
|
|
|
2023-09-17 16:26:48 +02:00
|
|
|
float GetFloat(int pos);
|
|
|
|
int GetInteger(int pos);
|
|
|
|
Listener *GetListener(int pos);
|
2016-03-27 11:49:47 +02:00
|
|
|
|
2023-09-17 16:26:48 +02:00
|
|
|
class PathNode *GetPathNode(int pos);
|
2016-03-27 11:49:47 +02:00
|
|
|
|
2023-05-29 01:33:07 +02:00
|
|
|
#ifdef WITH_SCRIPT_ENGINE
|
2023-09-17 16:26:48 +02:00
|
|
|
SimpleEntity *GetSimpleEntity(int pos);
|
2016-03-27 11:49:47 +02:00
|
|
|
#endif
|
|
|
|
|
2023-09-17 16:26:48 +02:00
|
|
|
str GetString(int pos);
|
|
|
|
str GetToken(int pos);
|
|
|
|
ScriptVariable& GetValue(int pos);
|
|
|
|
ScriptVariable& GetValue(void);
|
|
|
|
Vector GetVector(int pos);
|
2016-03-27 11:49:47 +02:00
|
|
|
|
2023-09-17 16:26:48 +02:00
|
|
|
class Waypoint *GetWaypoint(int pos);
|
2016-03-27 11:49:47 +02:00
|
|
|
|
2023-09-17 16:26:48 +02:00
|
|
|
qboolean IsEntityAt(int pos);
|
|
|
|
qboolean IsListenerAt(int pos);
|
|
|
|
qboolean IsNilAt(int pos);
|
|
|
|
qboolean IsNumericAt(int pos);
|
2023-05-29 01:33:07 +02:00
|
|
|
#ifdef WITH_SCRIPT_ENGINE
|
2023-09-17 16:26:48 +02:00
|
|
|
qboolean IsSimpleEntityAt(int pos);
|
2016-03-27 11:49:47 +02:00
|
|
|
#endif
|
2023-09-17 16:26:48 +02:00
|
|
|
qboolean IsStringAt(int pos);
|
|
|
|
qboolean IsVectorAt(int pos);
|
2016-03-27 11:49:47 +02:00
|
|
|
|
2023-09-17 16:26:48 +02:00
|
|
|
qboolean IsFromScript(void);
|
2016-03-27 11:49:47 +02:00
|
|
|
|
2023-09-17 16:26:48 +02:00
|
|
|
int NumArgs();
|
2016-03-27 11:49:47 +02:00
|
|
|
};
|
|
|
|
|
2023-09-17 16:26:48 +02:00
|
|
|
#define NODE_CANCEL 1
|
|
|
|
#define NODE_FIXED_EVENT 2
|
2016-03-27 11:49:47 +02:00
|
|
|
|
2023-09-17 16:26:48 +02:00
|
|
|
class EventQueueNode
|
|
|
|
{
|
2016-03-27 11:49:47 +02:00
|
|
|
public:
|
2023-09-17 16:26:48 +02:00
|
|
|
Event *event;
|
|
|
|
int inttime;
|
|
|
|
int flags;
|
|
|
|
SafePtr<Listener> m_sourceobject;
|
2016-03-27 11:49:47 +02:00
|
|
|
|
2023-09-17 16:26:48 +02:00
|
|
|
EventQueueNode *prev;
|
|
|
|
EventQueueNode *next;
|
2016-03-27 11:49:47 +02:00
|
|
|
|
|
|
|
#ifdef _DEBUG
|
2024-01-24 21:51:46 +01:00
|
|
|
const char *name;
|
2016-03-27 11:49:47 +02:00
|
|
|
#endif
|
|
|
|
|
2023-09-17 16:26:48 +02:00
|
|
|
EventQueueNode()
|
|
|
|
{
|
|
|
|
prev = this;
|
|
|
|
next = this;
|
2024-01-24 21:51:46 +01:00
|
|
|
|
|
|
|
#ifdef _DEBUG
|
|
|
|
name = NULL;
|
|
|
|
#endif
|
2023-09-17 16:26:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Listener *GetSourceObject(void) { return m_sourceobject; }
|
|
|
|
|
|
|
|
void SetSourceObject(Listener *obj) { m_sourceobject = obj; }
|
2016-03-27 11:49:47 +02:00
|
|
|
};
|
|
|
|
|
2023-09-17 16:26:48 +02:00
|
|
|
template<class Type1, class Type2>
|
2016-03-27 11:49:47 +02:00
|
|
|
class con_map;
|
|
|
|
|
2023-09-17 16:26:48 +02:00
|
|
|
using ConList = ContainerClass<SafePtr<Listener>>;
|
|
|
|
using eventMap = con_map<Event *, EventDef *>;
|
2016-03-27 11:49:47 +02:00
|
|
|
|
2023-09-17 16:26:48 +02:00
|
|
|
using ListenerPtr = SafePtr<Listener>;
|
2016-03-27 11:49:47 +02:00
|
|
|
|
|
|
|
class Listener : public Class
|
|
|
|
{
|
|
|
|
public:
|
2023-05-29 01:33:07 +02:00
|
|
|
#ifdef WITH_SCRIPT_ENGINE
|
2023-09-17 16:26:48 +02:00
|
|
|
con_set<const_str, ConList> *m_NotifyList;
|
|
|
|
con_set<const_str, ConList> *m_WaitForList;
|
|
|
|
con_set<const_str, ConList> *m_EndList;
|
|
|
|
ScriptVariableList *vars;
|
2016-03-27 11:49:47 +02:00
|
|
|
#endif
|
|
|
|
|
2023-09-17 16:26:48 +02:00
|
|
|
static bool EventSystemStarted;
|
2016-03-27 11:49:47 +02:00
|
|
|
|
|
|
|
private:
|
2023-05-29 01:33:07 +02:00
|
|
|
#ifdef WITH_SCRIPT_ENGINE
|
2023-09-17 16:26:48 +02:00
|
|
|
void ExecuteScriptInternal(Event *ev, ScriptVariable& scriptVariable);
|
|
|
|
void ExecuteThreadInternal(Event *ev, ScriptVariable& returnValue);
|
|
|
|
void WaitExecuteScriptInternal(Event *ev, ScriptVariable& returnValue);
|
|
|
|
void WaitExecuteThreadInternal(Event *ev, ScriptVariable& returnValue);
|
2016-03-27 11:49:47 +02:00
|
|
|
#endif
|
|
|
|
|
2023-09-17 16:26:48 +02:00
|
|
|
EventQueueNode *PostEventInternal(Event *ev, float delay, int flags);
|
2016-03-27 11:49:47 +02:00
|
|
|
|
|
|
|
public:
|
2023-09-17 16:26:48 +02:00
|
|
|
CLASS_PROTOTYPE(Listener);
|
2016-03-27 11:49:47 +02:00
|
|
|
|
2023-05-29 01:33:07 +02:00
|
|
|
#ifdef WITH_SCRIPT_ENGINE
|
2023-09-17 16:26:48 +02:00
|
|
|
/* Game functions */
|
|
|
|
virtual ScriptThread *CreateThreadInternal(const ScriptVariable& label);
|
|
|
|
virtual ScriptThread *CreateScriptInternal(const ScriptVariable& label);
|
|
|
|
virtual void StoppedNotify(void);
|
|
|
|
virtual void StartedWaitFor(void);
|
|
|
|
virtual void StoppedWaitFor(const_str name, bool bDeleting);
|
2016-03-27 11:49:47 +02:00
|
|
|
#endif
|
|
|
|
|
2023-09-17 16:26:48 +02:00
|
|
|
virtual Listener *GetScriptOwner(void);
|
2016-03-27 11:49:47 +02:00
|
|
|
|
2023-09-17 16:26:48 +02:00
|
|
|
Listener();
|
|
|
|
virtual ~Listener();
|
2016-03-27 11:49:47 +02:00
|
|
|
|
2023-09-17 16:26:48 +02:00
|
|
|
void Archive(Archiver& arc) override;
|
2016-03-27 11:49:47 +02:00
|
|
|
|
2023-09-17 16:26:48 +02:00
|
|
|
void CancelEventsOfType(Event *ev);
|
|
|
|
void CancelEventsOfType(Event& ev);
|
|
|
|
void CancelFlaggedEvents(int flags);
|
|
|
|
void CancelPendingEvents(void);
|
2016-03-27 11:49:47 +02:00
|
|
|
|
2023-09-17 16:26:48 +02:00
|
|
|
qboolean EventPending(Event& ev);
|
2016-03-27 11:49:47 +02:00
|
|
|
|
2023-09-17 16:26:48 +02:00
|
|
|
void PostEvent(Event *ev, float delay, int flags = 0);
|
|
|
|
void PostEvent(const Event& ev, float delay, int flags = 0);
|
2016-03-27 11:49:47 +02:00
|
|
|
|
2023-09-17 16:26:48 +02:00
|
|
|
qboolean PostponeAllEvents(float time);
|
|
|
|
qboolean PostponeEvent(Event& ev, float time);
|
2016-03-27 11:49:47 +02:00
|
|
|
|
2024-01-24 21:51:46 +01:00
|
|
|
bool ProcessEvent(const Event& ev);
|
2023-09-17 16:26:48 +02:00
|
|
|
bool ProcessEvent(Event *ev);
|
2024-01-24 21:51:46 +01:00
|
|
|
bool ProcessEvent(Event& ev);
|
2023-09-17 16:26:48 +02:00
|
|
|
ScriptVariable& ProcessEventReturn(Event *ev);
|
2016-03-27 11:49:47 +02:00
|
|
|
|
2023-09-17 16:26:48 +02:00
|
|
|
void ProcessContainerEvent(const Container<Event *>& conev);
|
2016-03-27 11:49:47 +02:00
|
|
|
|
2023-09-17 16:26:48 +02:00
|
|
|
qboolean ProcessPendingEvents(void);
|
2016-03-27 11:49:47 +02:00
|
|
|
|
2023-09-17 16:26:48 +02:00
|
|
|
bool ProcessScriptEvent(Event& ev);
|
|
|
|
bool ProcessScriptEvent(Event *ev);
|
2016-03-27 11:49:47 +02:00
|
|
|
|
2023-05-29 01:33:07 +02:00
|
|
|
#ifdef WITH_SCRIPT_ENGINE
|
2016-03-27 11:49:47 +02:00
|
|
|
|
2023-09-17 16:26:48 +02:00
|
|
|
void CreateVars(void);
|
|
|
|
void ClearVars(void);
|
|
|
|
ScriptVariableList *Vars(void);
|
|
|
|
|
|
|
|
bool BroadcastEvent(Event& event, ConList *listeners);
|
|
|
|
bool BroadcastEvent(str name, Event& event);
|
|
|
|
bool BroadcastEvent(const_str name, Event& event);
|
|
|
|
void CancelWaiting(str name);
|
|
|
|
void CancelWaiting(const_str name);
|
|
|
|
void CancelWaitingAll(void);
|
|
|
|
void CancelWaitingSources(const_str name, ConList& listeners, ConList& stoppedListeners);
|
|
|
|
|
|
|
|
void ExecuteThread(str scriptName, str label, Event *params = NULL);
|
|
|
|
void ExecuteThread(str scriptName, str label, Event& params);
|
|
|
|
|
|
|
|
void EndOn(str name, Listener *listener);
|
|
|
|
void EndOn(const_str name, Listener *listener);
|
|
|
|
void Notify(const char *name);
|
|
|
|
void Register(str name, Listener *listener);
|
|
|
|
void Register(const_str name, Listener *listener);
|
|
|
|
void RegisterSource(const_str name, Listener *listener);
|
|
|
|
void RegisterTarget(const_str name, Listener *listener);
|
|
|
|
void Unregister(str name);
|
|
|
|
void Unregister(const_str name);
|
|
|
|
void Unregister(str name, Listener *listener);
|
|
|
|
void Unregister(const_str name, Listener *listener);
|
|
|
|
void UnregisterAll(void);
|
|
|
|
bool UnregisterSource(const_str name, Listener *listener);
|
|
|
|
bool UnregisterTarget(const_str name, Listener *listener);
|
|
|
|
void UnregisterTargets(
|
|
|
|
const_str name, ConList& listeners, ConList& stoppedListeners, Container<const_str>& stoppedNames
|
|
|
|
);
|
|
|
|
void AbortRegistration(const_str name, Listener *l);
|
|
|
|
|
|
|
|
int RegisterSize(const_str name) const;
|
|
|
|
int RegisterSize(str name) const;
|
|
|
|
int WaitingSize(const_str name) const;
|
|
|
|
int WaitingSize(str name) const;
|
|
|
|
|
|
|
|
bool WaitTillDisabled(str s);
|
|
|
|
bool WaitTillDisabled(const_str s);
|
2016-03-27 11:49:47 +02:00
|
|
|
#endif
|
|
|
|
|
2023-09-17 16:26:48 +02:00
|
|
|
int GetFlags(Event *event) const;
|
|
|
|
qboolean ValidEvent(str name) const;
|
2016-03-27 11:49:47 +02:00
|
|
|
|
2023-09-17 16:26:48 +02:00
|
|
|
//
|
|
|
|
// Scripting functions
|
|
|
|
//
|
|
|
|
void CommandDelay(Event *ev);
|
2023-10-30 22:03:37 +01:00
|
|
|
void Remove(Event *ev);
|
|
|
|
void ScriptRemove(Event *ev);
|
2023-09-17 16:26:48 +02:00
|
|
|
void EventInheritsFrom(Event *ev);
|
|
|
|
void EventIsInheritedBy(Event *ev);
|
|
|
|
void GetClassname(Event *ev);
|
2016-03-27 11:49:47 +02:00
|
|
|
|
2023-05-29 01:33:07 +02:00
|
|
|
#ifdef WITH_SCRIPT_ENGINE
|
2023-09-17 16:26:48 +02:00
|
|
|
void CancelFor(Event *ev);
|
|
|
|
void CreateReturnThread(Event *ev);
|
|
|
|
void CreateThread(Event *ev);
|
|
|
|
void ExecuteReturnScript(Event *ev);
|
|
|
|
void ExecuteScript(Event *ev);
|
|
|
|
void EventDelayThrow(Event *ev);
|
|
|
|
void EventEndOn(Event *ev);
|
|
|
|
void EventGetOwner(Event *ev);
|
|
|
|
void EventNotify(Event *ev);
|
|
|
|
void EventThrow(Event *ev);
|
|
|
|
void EventUnregister(Event *ev);
|
|
|
|
void WaitCreateReturnThread(Event *ev);
|
|
|
|
void WaitCreateThread(Event *ev);
|
|
|
|
void WaitExecuteReturnScript(Event *ev);
|
|
|
|
void WaitExecuteScript(Event *ev);
|
|
|
|
void WaitTill(Event *ev);
|
|
|
|
void WaitTillTimeout(Event *ev);
|
|
|
|
void WaitTillAny(Event *ev);
|
|
|
|
void WaitTillAnyTimeout(Event *ev);
|
2016-03-27 11:49:47 +02:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2023-09-17 16:26:48 +02:00
|
|
|
qboolean IsNumeric(const char *str);
|
2016-03-27 11:49:47 +02:00
|
|
|
|
|
|
|
extern Event EV_DelayThrow;
|
|
|
|
extern Event EV_Delete;
|
|
|
|
extern Event EV_Remove;
|
|
|
|
extern Event EV_ScriptRemove;
|
|
|
|
extern Event EV_Throw;
|
|
|
|
|
|
|
|
extern Event EV_Listener_CreateThread;
|
|
|
|
extern Event EV_Listener_CreateReturnThread;
|
|
|
|
extern Event EV_Listener_ExecuteReturnScript;
|
|
|
|
extern Event EV_Listener_ExecuteScript;
|
|
|
|
extern Event EV_Listener_WaitCreateReturnThread;
|
|
|
|
|
2023-09-17 16:26:48 +02:00
|
|
|
extern int DisableListenerNotify;
|
2016-03-27 11:49:47 +02:00
|
|
|
|
2023-09-17 16:26:48 +02:00
|
|
|
extern cvar_t *g_showevents;
|
|
|
|
extern cvar_t *g_eventlimit;
|
|
|
|
extern cvar_t *g_timeevents;
|
|
|
|
extern cvar_t *g_watch;
|
|
|
|
extern cvar_t *g_eventstats;
|
2016-03-27 11:49:47 +02:00
|
|
|
|
2023-01-30 17:11:44 +01:00
|
|
|
extern MEM_BlockAlloc<Event> Event_allocator;
|
2016-03-27 11:49:47 +02:00
|
|
|
|
2023-09-17 16:26:48 +02:00
|
|
|
#if defined(GAME_DLL)
|
2016-03-27 11:49:47 +02:00
|
|
|
//
|
|
|
|
// game dll specific defines
|
|
|
|
//
|
2023-09-17 16:26:48 +02:00
|
|
|
# define EVENT_DebugPrintf gi.DebugPrintf
|
|
|
|
# define EVENT_DPrintf gi.DPrintf
|
|
|
|
# define EVENT_Printf gi.Printf
|
|
|
|
# define EVENT_time level.time
|
|
|
|
# define EVENT_msec level.inttime
|
|
|
|
# define EVENT_realtime gi.Milliseconds()
|
|
|
|
# define EVENT_Error gi.Error
|
2016-03-27 11:49:47 +02:00
|
|
|
|
2023-09-17 16:26:48 +02:00
|
|
|
# define EVENT_FILENAME "events.txt"
|
2016-03-27 11:49:47 +02:00
|
|
|
|
2023-09-17 16:26:48 +02:00
|
|
|
#elif defined(CGAME_DLL)
|
2016-03-27 11:49:47 +02:00
|
|
|
//
|
|
|
|
// cgame dll specific defines
|
|
|
|
//
|
2023-09-17 16:26:48 +02:00
|
|
|
# define EVENT_DebugPrintf cgi.DebugPrintf
|
|
|
|
# define EVENT_DPrintf cgi.Printf
|
|
|
|
# define EVENT_Printf cgi.Printf
|
|
|
|
# define EVENT_time (((float)cg.time / 1000.0f))
|
|
|
|
# define EVENT_msec cg.time
|
|
|
|
# define EVENT_realtime cgi.Milliseconds()
|
|
|
|
# define EVENT_Error cgi.Error
|
2016-03-27 11:49:47 +02:00
|
|
|
|
2023-09-17 16:26:48 +02:00
|
|
|
# define EVENT_FILENAME "cg_events.txt"
|
2016-03-27 11:49:47 +02:00
|
|
|
|
2023-09-17 16:26:48 +02:00
|
|
|
#elif defined(UI_LIB)
|
2016-03-27 11:49:47 +02:00
|
|
|
|
2023-09-17 16:26:48 +02:00
|
|
|
# define EVENT_DebugPrintf Com_DebugPrintf
|
|
|
|
# define EVENT_DPrintf Com_Printf
|
|
|
|
# define EVENT_Printf Com_Printf
|
|
|
|
# define EVENT_time (((float)cls.realtime / 1000.0f))
|
|
|
|
# define EVENT_msec cls.realtime
|
|
|
|
# define EVENT_realtime Sys_Milliseconds()
|
|
|
|
# define EVENT_Error Com_Error
|
2016-03-27 11:49:47 +02:00
|
|
|
|
2023-09-17 16:26:48 +02:00
|
|
|
# define EVENT_FILENAME "ui_events.txt"
|
2016-03-27 11:49:47 +02:00
|
|
|
|
|
|
|
#else
|
|
|
|
//
|
|
|
|
// client specific defines
|
|
|
|
//
|
2023-09-17 16:26:48 +02:00
|
|
|
# define EVENT_DebugPrintf Com_DebugPrintf
|
|
|
|
# define EVENT_DPrintf Com_Printf
|
|
|
|
# define EVENT_Printf Com_Printf
|
|
|
|
# define EVENT_time (((float)cls.realtime / 1000.0f))
|
|
|
|
# define EVENT_msec cls.realtime
|
|
|
|
# define EVENT_realtime Sys_Milliseconds()
|
|
|
|
# define EVENT_Error Com_Error
|
|
|
|
|
|
|
|
# define EVENT_FILENAME "cl_events.txt"
|
2016-03-27 11:49:47 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
void L_ClearEventList();
|
2023-09-17 16:26:48 +02:00
|
|
|
bool L_EventSystemStarted(void);
|
|
|
|
void L_InitEvents(void);
|
2016-03-27 11:49:47 +02:00
|
|
|
void L_ProcessPendingEvents();
|
2023-09-17 16:26:48 +02:00
|
|
|
void L_ShutdownEvents(void);
|
|
|
|
void L_ArchiveEvents(Archiver& arc);
|
|
|
|
void L_UnarchiveEvents(Archiver& arc);
|