這一次按預期工作:你能解釋這個switch()和()的一個等價物之間的區別嗎?
if (clu.raw.butsnum) {
int i;
for (i=0;i<clu.raw.butsnum;i++){
if (clu.raw.buts[i] & RI_MOUSE_BUTTON_1_DOWN)
Com_QueueEvent(0, SE_KEY, K_MOUSE1, qtrue, 0, NULL);
if (clu.raw.buts[i] & RI_MOUSE_BUTTON_2_DOWN)
Com_QueueEvent(0, SE_KEY, K_MOUSE2, qtrue, 0, NULL);
if (clu.raw.buts[i] & RI_MOUSE_BUTTON_3_DOWN)
Com_QueueEvent(0, SE_KEY, K_MOUSE3, qtrue, 0, NULL);
if (clu.raw.buts[i] & RI_MOUSE_BUTTON_4_DOWN)
Com_QueueEvent(0, SE_KEY, K_MOUSE4, qtrue, 0, NULL);
if (clu.raw.buts[i] & RI_MOUSE_BUTTON_5_DOWN)
Com_QueueEvent(0, SE_KEY, K_MOUSE5, qtrue, 0, NULL);
if (clu.raw.buts[i] & RI_MOUSE_BUTTON_1_UP)
Com_QueueEvent(0, SE_KEY, K_MOUSE1, qfalse, 0, NULL);
if (clu.raw.buts[i] & RI_MOUSE_BUTTON_2_UP)
Com_QueueEvent(0, SE_KEY, K_MOUSE2, qfalse, 0, NULL);
if (clu.raw.buts[i] & RI_MOUSE_BUTTON_3_UP)
Com_QueueEvent(0, SE_KEY, K_MOUSE3, qfalse, 0, NULL);
if (clu.raw.buts[i] & RI_MOUSE_BUTTON_4_UP)
Com_QueueEvent(0, SE_KEY, K_MOUSE4, qfalse, 0, NULL);
if (clu.raw.buts[i] & RI_MOUSE_BUTTON_5_UP)
Com_QueueEvent(0, SE_KEY, K_MOUSE5, qfalse, 0, NULL);
}
clu.raw.butsnum = 0;
但是這一次,
if (clu.raw.butsnum) {
short int down = qfalse;
int but = 0, i;
for (i = 0; i < clu.raw.butsnum; i++) {
switch(clu.raw.buts[i]) {
case RI_MOUSE_BUTTON_1_DOWN: down = qtrue; but = K_MOUSE1; break;
case RI_MOUSE_BUTTON_2_DOWN: down = qtrue; but = K_MOUSE2; break;
case RI_MOUSE_BUTTON_3_DOWN: down = qtrue; but = K_MOUSE3; break;
case RI_MOUSE_BUTTON_4_DOWN: down = qtrue; but = K_MOUSE4; break;
case RI_MOUSE_BUTTON_5_DOWN: down = qtrue; but = K_MOUSE5; break;
case RI_MOUSE_BUTTON_1_UP: down = qfalse; but = K_MOUSE1; break;
case RI_MOUSE_BUTTON_2_UP: down = qfalse; but = K_MOUSE2; break;
case RI_MOUSE_BUTTON_3_UP: down = qfalse; but = K_MOUSE3; break;
case RI_MOUSE_BUTTON_4_UP: down = qfalse; but = K_MOUSE4; break;
case RI_MOUSE_BUTTON_5_UP: down = qfalse; but = K_MOUSE5; break;
}
Com_QueueEvent(0, SE_KEY, but, down, 0, NULL);
}
}
clu.raw.butsnum = 0;
..sometimes「失去它」,如果某些「鼠標鍵」(在代碼)都沒有如果它們被擊得太快,就會被壓。
無論如何,我認爲代碼本身的相關性不大。
爲什麼那些代碼不會做完全相同的事情?