src/signs.h
branchNewGRF_ports
changeset 6743 cabfaa4a0295
parent 6732 ca1b466db422
child 6800 6c09e1e86fcb
equal deleted inserted replaced
6742:1337d6c9b97b 6743:cabfaa4a0295
     5 #ifndef SIGNS_H
     5 #ifndef SIGNS_H
     6 #define SIGNS_H
     6 #define SIGNS_H
     7 
     7 
     8 #include "oldpool.h"
     8 #include "oldpool.h"
     9 
     9 
    10 struct Sign {
    10 struct Sign;
       
    11 DECLARE_OLD_POOL(Sign, Sign, 2, 16000)
       
    12 
       
    13 struct Sign : PoolItem<Sign, SignID, &_Sign_pool> {
    11 	StringID     str;
    14 	StringID     str;
    12 	ViewportSign sign;
    15 	ViewportSign sign;
    13 	int32        x;
    16 	int32        x;
    14 	int32        y;
    17 	int32        y;
    15 	byte         z;
    18 	byte         z;
    16 	PlayerByte   owner; // placed by this player. Anyone can delete them though. OWNER_NONE for gray signs from old games.
    19 	PlayerByte   owner; // placed by this player. Anyone can delete them though. OWNER_NONE for gray signs from old games.
    17 
    20 
    18 	SignID       index;
    21 	/**
       
    22 	 * Creates a new sign
       
    23 	 */
       
    24 	Sign(StringID string = STR_NULL);
       
    25 
       
    26 	/** Destroy the sign */
       
    27 	~Sign();
       
    28 
       
    29 	bool IsValid() const { return this->str != STR_NULL; }
       
    30 
       
    31 	void QuickFree();
    19 };
    32 };
    20 
    33 
    21 enum {
    34 enum {
    22 	INVALID_SIGN = 0xFFFF,
    35 	INVALID_SIGN = 0xFFFF,
    23 };
    36 };
    24 
    37 
    25 extern SignID _new_sign_id;
    38 extern SignID _new_sign_id;
    26 
    39 
    27 DECLARE_OLD_POOL(Sign, Sign, 2, 16000)
       
    28 
    40 
    29 static inline SignID GetMaxSignIndex()
    41 static inline SignID GetMaxSignIndex()
    30 {
    42 {
    31 	/* TODO - This isn't the real content of the function, but
    43 	/* TODO - This isn't the real content of the function, but
    32 	 *  with the new pool-system this will be replaced with one that
    44 	 *  with the new pool-system this will be replaced with one that
    40 {
    52 {
    41 	extern uint _total_signs;
    53 	extern uint _total_signs;
    42 	return _total_signs;
    54 	return _total_signs;
    43 }
    55 }
    44 
    56 
    45 /**
    57 static inline bool IsValidSignID(uint index)
    46  * Check if a Sign really exists.
       
    47  */
       
    48 static inline bool IsValidSign(const Sign *si)
       
    49 {
    58 {
    50 	return si->str != STR_NULL;
    59 	return index < GetSignPoolSize() && GetSign(index)->IsValid();
    51 }
    60 }
    52 
    61 
    53 static inline bool IsValidSignID(uint index)
    62 #define FOR_ALL_SIGNS_FROM(ss, start) for (ss = GetSign(start); ss != NULL; ss = (ss->index + 1U < GetSignPoolSize()) ? GetSign(ss->index + 1U) : NULL) if (ss->IsValid())
    54 {
       
    55 	return index < GetSignPoolSize() && IsValidSign(GetSign(index));
       
    56 }
       
    57 
       
    58 void DestroySign(Sign *si);
       
    59 
       
    60 static inline void DeleteSign(Sign *si)
       
    61 {
       
    62 	DestroySign(si);
       
    63 	si->str = STR_NULL;
       
    64 }
       
    65 
       
    66 #define FOR_ALL_SIGNS_FROM(ss, start) for (ss = GetSign(start); ss != NULL; ss = (ss->index + 1U < GetSignPoolSize()) ? GetSign(ss->index + 1U) : NULL) if (IsValidSign(ss))
       
    67 #define FOR_ALL_SIGNS(ss) FOR_ALL_SIGNS_FROM(ss, 0)
    63 #define FOR_ALL_SIGNS(ss) FOR_ALL_SIGNS_FROM(ss, 0)
    68 
    64 
    69 VARDEF bool _sign_sort_dirty;
    65 VARDEF bool _sign_sort_dirty;
    70 
    66 
    71 void UpdateAllSignVirtCoords();
    67 void UpdateAllSignVirtCoords();