Files
player/Project/Src/MyWin/MyWinCore/mywin_timer.c

101 lines
1.6 KiB
C
Raw Normal View History

2025-06-27 00:32:57 +08:00
#include "mywin_inc.h"
2025-07-05 19:47:28 +08:00
//<2F><><EFBFBD>㶨ʱ<E3B6A8><CAB1>
2025-06-27 00:32:57 +08:00
int WIN_TimerReload (int timerId)
{
WIN_GetWinStruct()->softTimer[timerId-1].time_ms=0;
return 0;
}
2025-07-05 19:47:28 +08:00
//<2F><><EFBFBD>ö<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2025-06-27 00:32:57 +08:00
int WIN_SetTimerCycle (int timerId,int cycle)
{
WIN_GetWinStruct()->softTimer[timerId-1].cycle_ms=cycle;
return 0;
}
2025-07-05 19:47:28 +08:00
//<2F><><EFBFBD>Ӷ<EFBFBD>ʱ<EFBFBD><CAB1>,<2C>ɹ<EFBFBD><C9B9><EFBFBD><EFBFBD><EFBFBD>id<69><64>ʧ<EFBFBD>ܷ<EFBFBD><DCB7><EFBFBD>0
2025-06-27 00:32:57 +08:00
int WIN_CreatTimer (WIN_WindowStruct *win,u32 ms)
{
for (int i=0;i<WIN_SOFTTIMER_MAXNUM;i++)
{
if (WIN_GetWinStruct()->softTimer[i].win==0)
{
WIN_GetWinStruct()->softTimer[i].win=win;
WIN_GetWinStruct()->softTimer[i].cycle_ms=ms;
WIN_GetWinStruct()->softTimer[i].time_ms=0;
return i+1;
}
}
return 0;
}
2025-07-05 19:47:28 +08:00
//ɾ<><C9BE>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>ʧ<EFBFBD>ܷ<EFBFBD><DCB7><EFBFBD>-1<><31><EFBFBD>ɹ<EFBFBD><C9B9><EFBFBD><EFBFBD><EFBFBD>0
2025-06-27 00:32:57 +08:00
int WIN_DeleteTimer (int id)
{
if (id>=WIN_SOFTTIMER_MAXNUM) return -1;
if (id<=0) return -1;
WIN_GetWinStruct()->softTimer[id-1].win=0;
return 0;
}
2025-07-05 19:47:28 +08:00
//ɾ<><C9BE><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>ʱ<EFBFBD><CAB1>
2025-06-27 00:32:57 +08:00
int WIN_WinDeleteTimer (WIN_WindowStruct *win)
{
for (int i=0;i<WIN_SOFTTIMER_MAXNUM;i++)
{
if (WIN_GetWinStruct()->softTimer[i].win==win)
{
WIN_GetWinStruct()->softTimer[i].win=0;
}
}
return 0;
}
2025-07-05 19:47:28 +08:00
//<2F><>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2025-06-27 00:32:57 +08:00
void WIN_TimerWork (void)
{
WIN_MsgStruct msg={0};
u32 timePast=WIN_GetTimePast ();
for (int i=0;i<WIN_SOFTTIMER_MAXNUM;i++)
{
if (WIN_GetWinStruct()->softTimer[i].win)
{
WIN_GetWinStruct()->softTimer[i].time_ms+=timePast;
if (WIN_GetWinStruct()->softTimer[i].time_ms>=WIN_GetWinStruct()->softTimer[i].cycle_ms)
{
WIN_GetWinStruct()->softTimer[i].time_ms=0;
msg.msg=WIN_MSG_TIMER;
2025-07-05 19:47:28 +08:00
msg.data.v=i+1; //<2F><><EFBFBD>䶨ʱ<E4B6A8><CAB1>id
2025-06-27 00:32:57 +08:00
WIN_SendMsg (0,WIN_GetWinStruct()->softTimer[i].win,&msg);
}
}
}
}