Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions docs/syntax.txt
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,22 @@ int argb(int a,int r,int g,int b);
void DeleteEntities();
void ClearEvents();


SetEventHandlerForObject(object &object_ref, string event_name, string function_name, int post);
DelEventHandlerForObject(object &object_ref, string event_name, string function_name);

Event(string event_name, string format, ...);
EventForObject(object &object_ref, string event_name, string format, ...);

PostEvent(string event_name, int time, string format, ...); // post deffered event. time in ms
PostEventForObject(object &object_ref, string event_name, int time, string format, ...);
SetEventFormat(string event_name, string format);

// Will not be reset by ClearEvents()
SetEventStaticHandler(string event_name, string function_name, int post);
SetEventStaticHandlerForObject(object &object_ref, string event_name, string function_name, int post);


// COMMENTS

. Code send entity id "i" to script and it cames as aref variable into script (GetEventData())
3 changes: 1 addition & 2 deletions src/libs/core/include/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ class Core
virtual void Entity_SetAttributePointer(entid_t id_PTR, ATTRIBUTES *pA) = 0;
virtual uint32_t Entity_AttributeChanged(entid_t id_PTR, ATTRIBUTES *) = 0;
virtual ATTRIBUTES *Entity_GetAttributePointer(entid_t id_PTR) = 0;

// send message to an object
virtual uint64_t Send_Message(entid_t Destination, const char *Format, ...) = 0;

Expand All @@ -95,7 +94,7 @@ class Core
return Event(event_name, message);
}
virtual VDATA *Event(const std::string_view &event_name, MESSAGE &message) = 0;
virtual uint32_t PostEvent(const char *Event_name, uint32_t post_time, const char *Format, ...) = 0;
virtual uint32_t PostEvent(ATTRIBUTES * pObject, const char *Event_name, uint32_t post_time, const char *Format, ...) = 0;

virtual void *GetSaveData(const char *file_name, int32_t &data_size) = 0;

Expand Down
29 changes: 28 additions & 1 deletion src/libs/core/include/message.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
#include <cstdarg>
#include <cstring>
#include <variant>
#include <unordered_map>

#include "c_vector.h"
#include "entity.h"

class VDATA;
class DATA;
class VIRTUAL_COMPILER;
class VarTable;

namespace storm
{
Expand Down Expand Up @@ -57,13 +61,19 @@ class MESSAGE final
CVECTOR CVector();
const std::string &String();


bool Set(uint8_t value);
bool Set(uint16_t value);
bool Set(int32_t value);
bool Set(uint32_t value);
bool Set(uintptr_t value);
bool Set(float value);
bool Set(double value);
bool Set(std::string value);
bool SetEntity(entid_t value);
bool Set(VDATA *value);
bool Set(ATTRIBUTES *value);
bool Set(CVECTOR value);

void ValidateFormat(char c);
void Reset(const std::string_view &format);
Expand All @@ -84,10 +94,27 @@ class MESSAGE final
[[nodiscard]] std::string_view GetFormat() const;
[[nodiscard]] bool ParamValid() const;

private:
size_t GetParametersCount() const;
void GetData(DATA *vd, COMPILER *comp);
bool StoreData(ATTRIBUTES *attr, std::unordered_map<void *, std::pair<std::string, std::vector<size_t>>> &varIndex,
VIRTUAL_COMPILER *compiler) const;
static MESSAGE *LoadData(ATTRIBUTES *attr, VarTable &VarTab, VIRTUAL_COMPILER *compiler);
void FixEnitiyIDs();

ATTRIBUTES *GetThisObject();
void SetThisObject(ATTRIBUTES *);
private:
static storm::MessageParam GetParamValue(const char c, va_list &args);

std::string format_;
std::vector<storm::MessageParam> params_;
int32_t index{};
bool hasThisObject_{false};
};

ATTRIBUTES *LoadAttributesRef(ATTRIBUTES *attr, VarTable &VarTab, VIRTUAL_COMPILER *compiler);

//false - local variable reference; otherwise - true
bool StoreAttributesRef(ATTRIBUTES *attr, const ATTRIBUTES *val,
std::unordered_map<void *, std::pair<std::string, std::vector<size_t>>> &varIndex,
VIRTUAL_COMPILER *compiler);
Loading