450 |
struct VMRelPtr { |
struct VMRelPtr { |
451 |
void** base; ///< Base pointer. |
void** base; ///< Base pointer. |
452 |
int offset; ///< Offset (in bytes) relative to base pointer. |
int offset; ///< Offset (in bytes) relative to base pointer. |
453 |
|
bool readonly; ///< Whether the pointed data may be modified or just be read. |
454 |
}; |
}; |
455 |
|
|
456 |
/** @brief Pointer to built-in VM integer variable (of C/C++ type int). |
/** @brief Pointer to built-in VM integer variable (of C/C++ type int). |
478 |
VMIntRelPtr() { |
VMIntRelPtr() { |
479 |
base = NULL; |
base = NULL; |
480 |
offset = 0; |
offset = 0; |
481 |
|
readonly = false; |
482 |
} |
} |
483 |
VMIntRelPtr(const VMRelPtr& data) { |
VMIntRelPtr(const VMRelPtr& data) { |
484 |
base = data.base; |
base = data.base; |
485 |
offset = data.offset; |
offset = data.offset; |
486 |
|
readonly = false; |
487 |
} |
} |
488 |
virtual int evalInt() { return *(int*)&(*(uint8_t**)base)[offset]; } |
virtual int evalInt() { return *(int*)&(*(uint8_t**)base)[offset]; } |
489 |
virtual void assign(int i) { *(int*)&(*(uint8_t**)base)[offset] = i; } |
virtual void assign(int i) { *(int*)&(*(uint8_t**)base)[offset] = i; } |
566 |
#define DECLARE_VMINT(basePtr, T_struct, T_member) ( \ |
#define DECLARE_VMINT(basePtr, T_struct, T_member) ( \ |
567 |
(VMRelPtr) { \ |
(VMRelPtr) { \ |
568 |
(void**) &basePtr, \ |
(void**) &basePtr, \ |
569 |
offsetof(T_struct, T_member) \ |
offsetof(T_struct, T_member), \ |
570 |
|
false \ |
571 |
} \ |
} \ |
572 |
) \ |
) \ |
573 |
|
|
574 |
|
/** |
575 |
|
* Same as DECLARE_VMINT(), but this one defines the VMIntRelPtr and |
576 |
|
* VMInt8RelPtr structures to be of read-only type. That means the script |
577 |
|
* parser will abort any script at parser time if the script is trying to |
578 |
|
* modify such a read-only built-in variable. |
579 |
|
* |
580 |
|
* @b NOTE: this is only intended for built-in read-only variables that |
581 |
|
* may change during runtime! If your built-in variable's data is rather |
582 |
|
* already available at parser time and won't change during runtime, then |
583 |
|
* you should rather register a built-in constant in your VM class instead! |
584 |
|
* |
585 |
|
* @see ScriptVM::builtInConstIntVariables() |
586 |
|
*/ |
587 |
|
#define DECLARE_VMINT_READONLY(basePtr, T_struct, T_member) ( \ |
588 |
|
(VMRelPtr) { \ |
589 |
|
(void**) &basePtr, \ |
590 |
|
offsetof(T_struct, T_member), \ |
591 |
|
true \ |
592 |
|
} \ |
593 |
|
) \ |
594 |
|
|
595 |
/** @brief Built-in VM 8 bit integer array variable. |
/** @brief Built-in VM 8 bit integer array variable. |
596 |
* |
* |
597 |
* Used for defining built-in integer array script variables (8 bit per |
* Used for defining built-in integer array script variables (8 bit per |