X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fcommon%2Fnotifications%2Fall.qc;h=557a1b00cabf3aa0577c8a4b5b37f8e878fef96a;hb=8986f3650549d3b642a5a91b71dbaed718c25714;hp=e2c1e185afbea1b4e16e5f0d1599327bd95023bd;hpb=6c4bdd5eeea06db69a457997de24bef84b4eaf93;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/common/notifications/all.qc b/qcsrc/common/notifications/all.qc index e2c1e185a..557a1b00c 100644 --- a/qcsrc/common/notifications/all.qc +++ b/qcsrc/common/notifications/all.qc @@ -1,4 +1,5 @@ #include "all.qh" + #if defined(CSQC) #include #elif defined(MENUQC) @@ -6,10 +7,9 @@ #include #include #include - #include #include - #include #include + #include #endif // ================================================ @@ -79,6 +79,9 @@ string Notification_CheckArgs( bool Notification_ShouldSend(NOTIF broadcast, entity to_client, entity other_client) { + if(!IS_REAL_CLIENT(to_client)) + return false; + switch (broadcast) { case NOTIF_ONE: @@ -447,7 +450,8 @@ void Create_Notification_Entity_Annce(entity notif, float channel, string snd, float vol, - float position) + float position, + float queuetime) { // Set MSG_ANNCE information and handle precaching #ifdef CSQC @@ -463,6 +467,7 @@ void Create_Notification_Entity_Annce(entity notif, notif.nent_snd = strzone(snd); notif.nent_vol = vol; notif.nent_position = position; + notif.nent_queuetime = queuetime; } } else @@ -759,12 +764,12 @@ void Create_Notification_Entity_Choice(entity notif, // used by MSG_CHOICE to build list of choices #ifdef SVQC -void Notification_GetCvars(entity this) +void Notification_GetCvars(entity this, entity store) { FOREACH(Notifications, it.nent_type == MSG_CHOICE && (!it.nent_teamnum || it.nent_teamnum == NUM_TEAM_1), { GetCvars_handleFloat( this, - CS(this), + store, get_cvars_s, get_cvars_f, msg_choice_choices[it.nent_choice_idx], @@ -835,14 +840,14 @@ void Dump_Notifications(int fh, bool alsoprint) } }); - NOTIF_WRITE(sprintf("\n// MSG_ANNCE notifications (count = %d):\n", NOTIF_ANNCE_COUNT)); + NOTIF_WRITE(sprintf("\n// MSG_ANNCE notifications:\n")); FOREACH(Notifications, it.nent_type == MSG_ANNCE && (!it.nent_teamnum || it.nent_teamnum == NUM_TEAM_1), { NOTIF_WRITE_ENTITY(it, "0 = disabled, 1 = enabled if gentle mode is off, 2 = always enabled" ); }); - NOTIF_WRITE(sprintf("\n// MSG_INFO notifications (count = %d):\n", NOTIF_INFO_COUNT)); + NOTIF_WRITE(sprintf("\n// MSG_INFO notifications:\n")); FOREACH(Notifications, it.nent_type == MSG_INFO && (!it.nent_teamnum || it.nent_teamnum == NUM_TEAM_1), { NOTIF_WRITE_ENTITY(it, "0 = off, 1 = print to console, " @@ -850,21 +855,21 @@ void Dump_Notifications(int fh, bool alsoprint) ); }); - NOTIF_WRITE(sprintf("\n// MSG_CENTER notifications (count = %d):\n", NOTIF_CENTER_COUNT)); + NOTIF_WRITE(sprintf("\n// MSG_CENTER notifications:\n")); FOREACH(Notifications, it.nent_type == MSG_CENTER && (!it.nent_teamnum || it.nent_teamnum == NUM_TEAM_1), { NOTIF_WRITE_ENTITY(it, "0 = off, 1 = centerprint" ); }); - NOTIF_WRITE(sprintf("\n// MSG_MULTI notifications (count = %d):\n", NOTIF_MULTI_COUNT)); + NOTIF_WRITE(sprintf("\n// MSG_MULTI notifications:\n")); FOREACH(Notifications, it.nent_type == MSG_MULTI && (!it.nent_teamnum || it.nent_teamnum == NUM_TEAM_1), { NOTIF_WRITE_ENTITY(it, "Enable this multiple notification" ); }); - NOTIF_WRITE(sprintf("\n// MSG_CHOICE notifications (count = %d):\n", NOTIF_CHOICE_COUNT)); + NOTIF_WRITE(sprintf("\n// MSG_CHOICE notifications:\n")); FOREACH(Notifications, it.nent_type == MSG_CHOICE && (!it.nent_teamnum || it.nent_teamnum == NUM_TEAM_1), { NOTIF_WRITE_ENTITY_CHOICE(it, "Choice for this notification 0 = off, 1 = default message, 2 = verbose message", @@ -959,11 +964,8 @@ void Dump_Notifications(int fh, bool alsoprint) "Don't show attacker spree information in MSG_INFO messages if it isn't an achievement" ); - NOTIF_WRITE(sprintf( - ( - "\n// Notification counts (total = %d): " - "MSG_ANNCE = %d, MSG_INFO = %d, MSG_CENTER = %d, MSG_MULTI = %d, MSG_CHOICE = %d\n" - ), + LOG_INFOF("Notification counts (total = %d): " + "MSG_ANNCE = %d, MSG_INFO = %d, MSG_CENTER = %d, MSG_MULTI = %d, MSG_CHOICE = %d\n", ( NOTIF_ANNCE_COUNT + NOTIF_INFO_COUNT + @@ -976,7 +978,7 @@ void Dump_Notifications(int fh, bool alsoprint) NOTIF_CENTER_COUNT, NOTIF_MULTI_COUNT, NOTIF_CHOICE_COUNT - )); + ); #undef NOTIF_WRITE_HARDCODED #undef NOTIF_WRITE_ENTITY #undef NOTIF_WRITE @@ -1177,6 +1179,55 @@ void Local_Notification_centerprint_Add( #endif centerprint_Add(ORDINAL(cpid), input, stof(arg_slot[0]), stof(arg_slot[1])); } + +void Local_Notification_Queue_Run(MSG net_type, entity notif) +{ + switch (net_type) + { + case MSG_ANNCE: + { + Local_Notification_sound(notif.nent_channel, notif.nent_snd, notif.nent_vol, notif.nent_position); + break; + } + } +} + +void Local_Notification_Queue_Add(MSG net_type, entity notif, float queue_time) +{ + if(queue_time == -1 || time > notif_queue_next_time) { + // Run immediately + Local_Notification_Queue_Run(net_type, notif); + if(queue_time >= 0) + notif_queue_next_time = time + (queue_time == 0 ? soundlength(AnnouncerFilename(notif.nent_snd)) : queue_time); + } else { + // Put in queue + if(notif_queue_length >= NOTIF_QUEUE_MAX) return; + + notif_queue_type[notif_queue_length] = net_type; + notif_queue_entity[notif_queue_length] = notif; + notif_queue_time[notif_queue_length] = notif_queue_next_time; + + notif_queue_next_time += queue_time; + ++notif_queue_length; + } +} + +void Local_Notification_Queue_Process() +{ + if(!notif_queue_length || notif_queue_time[0] > time) + return; + + Local_Notification_Queue_Run(notif_queue_type[0], notif_queue_entity[0]); + + // Shift queue to the left + --notif_queue_length; + for (int j = 0; j < notif_queue_length; j++) { + notif_queue_type[j] = notif_queue_type[j+1]; + notif_queue_entity[j] = notif_queue_entity[j+1]; + notif_queue_time[j] = notif_queue_time[j+1]; + } +} + #endif void Local_Notification(MSG net_type, Notification net_name, ...count) @@ -1249,7 +1300,7 @@ void Local_Notification(MSG net_type, Notification net_name, ...count) case MSG_ANNCE: { #ifdef CSQC - Local_Notification_sound(notif.nent_channel, notif.nent_snd, notif.nent_vol, notif.nent_position); + Local_Notification_Queue_Add(net_type, notif, notif.nent_queuetime); #else backtrace("MSG_ANNCE on server?... Please notify Samual immediately!\n"); #endif @@ -1357,6 +1408,7 @@ void Local_Notification(MSG net_type, Notification net_name, ...count) found_choice.nent_floatcount, s1, s2, s3, s4, f1, f2, f3, f4); + break; } } } @@ -1520,7 +1572,7 @@ void Send_Notification( MSG net_type, Notification net_name, ...count) { - if (broadcast != NOTIF_ALL && broadcast != NOTIF_ALL_EXCEPT && !IS_REAL_CLIENT(client)) return; + if (broadcast == NOTIF_ONE_ONLY && !IS_REAL_CLIENT(client)) return; entity notif = net_name; string parms = sprintf("%s, '%s', %s, %s", Get_Notif_BroadcastName(broadcast), @@ -1603,7 +1655,7 @@ void Send_Notification( #define RECURSE_FROM_CHOICE(ent,action) MACRO_BEGIN \ if (notif.nent_challow_var && (warmup_stage || (notif.nent_challow_var == 2))) { \ - switch (CS(ent).msg_choice_choices[net_name.nent_choice_idx]) \ + switch (CS_CVAR(ent).msg_choice_choices[net_name.nent_choice_idx]) \ { \ case 1: found_choice = notif.nent_optiona; break; \ case 2: found_choice = notif.nent_optionb; break; \ @@ -1634,7 +1686,7 @@ void Send_Notification( } default: { - FOREACH_CLIENT(IS_REAL_CLIENT(it) && Notification_ShouldSend(broadcast, it, client), { + FOREACH_CLIENT(Notification_ShouldSend(broadcast, it, client), { RECURSE_FROM_CHOICE(it, continue); }); break;