From: TimePath Date: Wed, 2 Mar 2016 11:53:57 +0000 (+1100) Subject: Notifications: strong typing X-Git-Tag: xonotic-v0.8.2~1132^2~9 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=158be54749387b43656e6757fb24917689266063;p=xonotic%2Fxonotic-data.pk3dir.git Notifications: strong typing --- diff --git a/qcsrc/common/notifications.qc b/qcsrc/common/notifications.qc index ed54380be..67a33b419 100644 --- a/qcsrc/common/notifications.qc +++ b/qcsrc/common/notifications.qc @@ -86,7 +86,7 @@ string Notification_CheckArgs_TypeName(float net_type, float net_name) #ifdef SVQC string Notification_CheckArgs( - float broadcast, entity client, + NOTIF broadcast, entity client, float net_type, float net_name) { // check supplied broadcast, target, type, and name for errors @@ -138,7 +138,7 @@ string Notification_CheckArgs( return checkargs; } -float Notification_ShouldSend(float broadcast, entity to_client, entity other_client) +float Notification_ShouldSend(NOTIF broadcast, entity to_client, entity other_client) { switch(broadcast) { @@ -1750,7 +1750,7 @@ bool Net_Write_Notification(entity this, entity client, int sf) } void Kill_Notification( - float broadcast, entity client, + NOTIF broadcast, entity client, float net_type, float net_name) { #ifdef NOTIFICATIONS_DEBUG @@ -1843,7 +1843,7 @@ void Kill_Notification( } void Send_Notification( - float broadcast, entity client, + NOTIF broadcast, entity client, float net_type, float net_name, ...count) { @@ -1926,7 +1926,7 @@ void Send_Notification( #ifdef NOTIFICATIONS_DEBUG Get_Notif_BroadcastName(broadcast); #else - ftos(broadcast); + ftos(ORDINAL(broadcast)); #endif backtrace(sprintf( strcat( @@ -1953,7 +1953,7 @@ void Send_Notification( #ifdef NOTIFICATIONS_DEBUG Get_Notif_BroadcastName(broadcast); #else - ftos(broadcast); + ftos(ORDINAL(broadcast)); #endif backtrace(sprintf( strcat( @@ -2084,7 +2084,7 @@ void Send_Notification( // WOVA = Without Variable Arguments void Send_Notification_WOVA( - float broadcast, entity client, + NOTIF broadcast, entity client, float net_type, float net_name, float stringcount, float floatcount, string s1, string s2, string s3, string s4, @@ -2118,7 +2118,7 @@ void Send_Notification_WOVA( // WOCOVA = Without Counts Or Variable Arguments void Send_Notification_WOCOVA( - float broadcast, entity client, + NOTIF broadcast, entity client, float net_type, float net_name, string s1, string s2, string s3, string s4, float f1, float f2, float f3, float f4) diff --git a/qcsrc/common/notifications.qh b/qcsrc/common/notifications.qh index 51690b04e..ba7371fce 100644 --- a/qcsrc/common/notifications.qh +++ b/qcsrc/common/notifications.qh @@ -168,28 +168,30 @@ float prev_soundtime; #endif #ifdef SVQC // SERVER ONLY -const float NOTIF_ONE = 1; -const float NOTIF_ONE_ONLY = 2; -const float NOTIF_TEAM = 3; -const float NOTIF_TEAM_EXCEPT = 4; -const float NOTIF_ALL = 5; -const float NOTIF_ALL_EXCEPT = 6; +ENUMCLASS(NOTIF) + CASE(NOTIF, ONE) + CASE(NOTIF, ONE_ONLY) + CASE(NOTIF, TEAM) + CASE(NOTIF, TEAM_EXCEPT) + CASE(NOTIF, ALL) + CASE(NOTIF, ALL_EXCEPT) +ENUMCLASS_END(NOTIF) void Kill_Notification( - float broadcast, entity client, + NOTIF broadcast, entity client, float net_type, float net_name); void Send_Notification( - float broadcast, entity client, + NOTIF broadcast, entity client, float net_type, float net_name, ...count); void Send_Notification_WOVA( - float broadcast, entity client, + NOTIF broadcast, entity client, float net_type, float net_name, float stringcount, float floatcount, string s1, string s2, string s3, string s4, float f1, float f2, float f3, float f4); void Send_Notification_WOCOVA( - float broadcast, entity client, + NOTIF broadcast, entity client, float net_type, float net_name, string s1, string s2, string s3, string s4, float f1, float f2, float f3, float f4); @@ -640,7 +642,9 @@ entity msg_choice_notifs[NOTIF_CHOICE_MAX]; .entity nent_optionb; // networked notification entity values -.float nent_broadcast; +#ifdef SVQC +.NOTIF nent_broadcast; +#endif .entity nent_client; .float nent_net_type; .float nent_net_name; diff --git a/qcsrc/lib/enumclass.qh b/qcsrc/lib/enumclass.qh index 412e9db6b..26956d3a5 100644 --- a/qcsrc/lib/enumclass.qh +++ b/qcsrc/lib/enumclass.qh @@ -11,13 +11,16 @@ #define ENUMCLASS(id) typedef int id; enum { #define CASE(class, id) class##_##id, #define ENUMCLASS_END(id) }; +#define ORDINAL(it) (it) #else // edict overhead mode, use this for type checking -#define ENUMCLASS(id) CLASS(id, Object) -#define CASE(class, id) class class##_##id; STATIC_INIT(class##_##id) { class##_##id = NEW(class); } +.int enum_ordinal; +#define ENUMCLASS(id) CLASS(id, Object) int id##_count; +#define CASE(class, id) class class##_##id; STATIC_INIT(class##_##id) { entity e = class##_##id = NEW(class); e.enum_ordinal = class##_count++; } #define ENUMCLASS_END(id) ENDCLASS(id) +#define ORDINAL(it) ((it).enum_ordinal) #endif