Jump to content
  • Advertisement
Sign in to follow this  
cambalinho

timeSetEvent(): can i change the timers limit?

This topic is 883 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i'm creating a Timer class:

class Timer
{

private:
    static unsigned int TimerCount;
    UINT_PTR timerid=0;
    UINT m_uResolution=0;
    unsigned int TimerID=0;
    DWORD intInterval=0;

    static void CALLBACK MultiMediaProcedure(UINT wTimerID, UINT msg, DWORD_PTR dwUser, DWORD dw1, DWORD dw2)
    {
        Timer* obj =(Timer*) dwUser;
        if(obj!=NULL && obj->timerprocedure!=NULL)
            obj->timerprocedure();
        else
            DebugText("MultiMediaProcedure: timer not activated");
    }

public:

    std::function<void()> timerprocedure=EmptyEvent;
    Timer(std::function<void()> tmrprocedure=EmptyEvent)
    {
        TimerCount+=1;
        TimerID=TimerCount-1;
        timerprocedure=tmrprocedure;
    }

    void Stop()
    {
        if(timerid!=0)
        {
            if(timeKillEvent(timerid)==MMSYSERR_INVALPARAM)
                DebugText("error on destroying the timer: " + to_string(GetLastError()));
            timeEndPeriod (m_uResolution);
            timerid=0;
        }
    }

    DWORD GetInterval()
    {
        return intInterval;
    }

    void SetInterval(DWORD uintInterval)
    {
        intInterval = uintInterval;
    }

    property <DWORD> Interval{GetProperty(Timer::GetInterval),SetProperty(Timer::SetInterval)};

    void Start()
    {
        Stop();
        TIMECAPS tc;
        timeGetDevCaps(&tc, sizeof(TIMECAPS));
        m_uResolution = tc.wPeriodMin;
        timeBeginPeriod(m_uResolution);
        timerid = timeSetEvent(intInterval, m_uResolution, Timer::MultiMediaProcedure, (DWORD_PTR)this, TIME_PERIODIC);
        if (timerid==NULL)
        {
            DebugText("No timer Started: " + to_string(GetLastError()));
        }
    }

    ~Timer()
    {
        if(timerid!=0)
            Stop();
        TimerCount-=1;
    }
};
unsigned int Timer::TimerCount=0;

these class works fine. but the timeSetEvent() have limits of timers. can anyone tell me if i can change that limit?

i use timeSetEvent(), because it's the only one that works fine for my situation

Share this post


Link to post
Share on other sites
Advertisement

You probably should not be using timeSetEvent for this. Not only is it deprecated, it's got limitations like you're running up against that are hard to control. The function that replaces it is CreateTimeQueueTimer. It's possible timeSetEvent is running into the same threadpool worker limit described therein, in which case you can perhaps adjust it by using WT_SET_MAX_THREADPOOL_THREAD, but this has potentially significant implications and probably isn't the best idea.

 

You may be better off driving your timer system off a custom implementation based on your game's high resolution update timer, as it will be more flexible.

 

Note that you also have several bugs in this code related to concurrency potential (your timer count update is unguarded and your timer ID assignment is based on it, both of which can cause bugs such as incorrect counts or duplicate timer IDs) and use of the time* APIs (you call timeBeginPeriod every time a timer starts, potentially overriding the previously set global resolution if its lower, and you never call timeEndPeriod. You must match each begin call with an end call that provides the same period value, per the documentation.

Edited by Josh Petrie

Share this post


Link to post
Share on other sites

- the interval between frames(animated gif's) can be diferent;

- i can't use CreateTimeQueueTimer , because i can't put it to work... only errors or don't starts:(

- the timeEndPeriod() is always called, depending on timerid value.

i don't know use WT_SET_MAX_THREADPOOL_THREAD. what i know is that it's a const, nothing more i know

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!