Claude Chappe' Curse - A C Game
Logo Institut d'Informatique Claude Chappe Logo Université de Le Mans Logo Raeptor Production
 
Loading...
Searching...
No Matches
scripts.h
Go to the documentation of this file.
1#include <io/input.h>
2#include <scripts/signals.h>
3struct Window;
4
14#ifndef SCRIPTS_H
15#define SCRIPTS_H
16
20#define NODE_FUNC_PARAMS struct Node *this, va_list args
21
25#define NODE_FUNC_RETURN void
26
30#define GET_READY_PARAMETERS() float delta = (float) GET_PARAMETER(double); (void) delta
31
35#define GET_SIGNAL() Signal signal = (Signal) GET_PARAMETER(int); (void) signal
36
41#define GET_PARAMETER(type) va_arg(args, type)
42
46#define GET_AREA_SIGNAL_PARAMETERS() ;int sigId = GET_PARAMETER(int); Node *other = (Node *) GET_PARAMETER(Node *); float distance = (float) GET_PARAMETER(double); float *impactPoint = (float *) GET_PARAMETER(float *); int offset = GET_PARAMETER(int); (void) sigId; (void) other; (void) distance; (void) impactPoint; (void) offset;
47
53#define MALLOC_ATTRIBUTE(node, x) if (!node->attribute) { \
54 node->attribute = malloc(sizeof(BehaviorAttribute) * x); \
55 POINTER_CHECK(node->attribute); \
56 node->attributes_count = x; \
57 for (int i = 0; i < x; i++) memset(&node->attribute[i], 0, sizeof(union BehaviorAttribute)); \
58 }
59
64#define SET_ATTRIBUTES_COUNT(x) MALLOC_ATTRIBUTE(this, x)
65
70#define NEW_SCRIPT(script_name) NODE_FUNC_RETURN script_name(NODE_FUNC_PARAMS) {
71
76#define END_SCRIPT(script_name) }; \
77static __attribute__((constructor)) void __anon_ctor_##script_name(void) {\
78 Game.scripts = realloc(Game.scripts, sizeof(Script) * (__scriptIndex__ + 1));\
79 Game.scripts[__scriptIndex__].name = #script_name;\
80 Game.scripts[__scriptIndex__++].script = script_name;\
81}
82
87typedef union BehaviorAttribute {
88 int i;
89 float f;
90 bool b;
91 void *p;
92 struct Node *node;
94
100
105typedef struct Script {
107 char * name;
108} Script;
109
120
126
131extern int __scriptIndex__;
132
133#endif // SCRIPTS_H
Represents a node in the tree structure.
Definition node.class.c:26
ScriptFunc Behavior[BEHAVIOR_SCRIPT_COUNT]
Array of script functions for different behavior scripts.
Definition scripts.h:125
#define NODE_FUNC_PARAMS
Macro to define the parameters for a node function.
Definition scripts.h:20
int __scriptIndex__
Global index for tracking the number of registered scripts.
Definition scripts.c:1
NODE_FUNC_RETURN(* ScriptFunc)(NODE_FUNC_PARAMS)
Function pointer type for script functions.
Definition scripts.h:99
BehaviorScripts
Enumeration of different behavior script types.
Definition scripts.h:114
@ BEHAVIOR_SCRIPT_SIGNAL
Definition scripts.h:117
@ BEHAVIOR_SCRIPT_READY
Definition scripts.h:115
@ BEHAVIOR_SCRIPT_UPDATE
Definition scripts.h:116
@ BEHAVIOR_SCRIPT_COUNT
Definition scripts.h:118
#define NODE_FUNC_RETURN
Macro to define the return type for a node function.
Definition scripts.h:25
Signal and slot system for C projects.
Structure representing a script with a function and a name.
Definition scripts.h:105
char * name
Definition scripts.h:107
ScriptFunc script
Definition scripts.h:106
Structure representing the SDL window and its associated OpenGL context.
Definition window.h:51
Union representing different types of behavior attributes.
Definition scripts.h:87
bool b
Definition scripts.h:90
int i
Definition scripts.h:88
struct Node * node
Definition scripts.h:92
float f
Definition scripts.h:89
void * p
Definition scripts.h:91