Click here to Skip to main content
15,899,556 members
Home / Discussions / C#
   

C#

 
AnswerRe: Porting this to event-based? Pin
Nader Elshehabi24-Sep-06 12:44
Nader Elshehabi24-Sep-06 12:44 
GeneralRe: Porting this to event-based? Pin
Lord Kixdemp24-Sep-06 14:27
Lord Kixdemp24-Sep-06 14:27 
GeneralRe: Porting this to event-based? Pin
Nader Elshehabi24-Sep-06 14:54
Nader Elshehabi24-Sep-06 14:54 
GeneralRe: Porting this to event-based? Pin
Lord Kixdemp24-Sep-06 15:13
Lord Kixdemp24-Sep-06 15:13 
GeneralRe: Porting this to event-based? Pin
Nader Elshehabi24-Sep-06 15:30
Nader Elshehabi24-Sep-06 15:30 
GeneralRe: Porting this to event-based? Pin
Lord Kixdemp25-Sep-06 11:25
Lord Kixdemp25-Sep-06 11:25 
GeneralRe: Porting this to event-based? Pin
Nader Elshehabi25-Sep-06 11:44
Nader Elshehabi25-Sep-06 11:44 
GeneralRe: Porting this to event-based? Pin
Lord Kixdemp25-Sep-06 14:27
Lord Kixdemp25-Sep-06 14:27 
That's exactly what I'm doing... Frown | :( Here's my KeyDown/KeyUp events:

private void OnKeyboardDown(object sender, KeyboardEventArgs e)
{
    // Don't do anything if we can't process input
    if (!canRespond) return;

    switch (e.Key)
    {
        // Arrows
        case Key.LeftArrow:
            this.lKey = true;
            break;
        case Key.RightArrow:
            this.rKey = true;
            break;
        case Key.UpArrow:
            this.uKey = true;
            break;
        case Key.DownArrow:
            this.dKey = true;
            break;

            // Press Shift to start running
        case Key.LeftShift:
            this.running = true;
            break;
    }
}

private void OnKeyboardUp(object sender, KeyboardEventArgs e)
{
    // Don't do anything if we can't process input
    if (!canRespond) return;

    switch (e.Key)
    {
        // Arrows
        case Key.LeftArrow:
            this.lKey = false;
            break;
        case Key.RightArrow:
            this.rKey = false;
            break;
        case Key.UpArrow:
            this.uKey = false;
            break;
        case Key.DownArrow:
            this.dKey = false;
            break;

        // Release Shift to stop running
        case Key.LeftShift:
            this.running = false;
            break;

        // Press Esc to quit
        case Key.Escape:
            On = false;
            break;
    }
}


And here's my main loop:

public void Loop()
{
    while (On)
    {
        float t = 0.0f;
        const float dt = 30;
        float currentTime = 0.0f;
        float accumulator = 0.0f;

        // Get the current time
        float newTime = SdlDotNet.Timer.TicksElapsed;

        float deltaTime = newTime - currentTime;
        currentTime = newTime;

        accumulator += deltaTime;

        while (accumulator >= dt)
        {
            canRespond = true;
            t += dt;
            accumulator -= dt;
        }
        canRespond = false;

        Render();

        // Sleep a bit so we don't use 100% CPU
        Thread.Sleep(10);
    }

    Quit(null, null);
}


See, if canRespond is false, the events don't execute...

Is that what you meant or did I misunderstand? Poke tongue | ;-P Thanks! Wink | ;)

Windows Calculator told me I will die at 28. Frown | :(

GeneralRe: Porting this to event-based? Pin
Nader Elshehabi25-Sep-06 14:36
Nader Elshehabi25-Sep-06 14:36 
GeneralRe: Porting this to event-based? Pin
Lord Kixdemp25-Sep-06 15:02
Lord Kixdemp25-Sep-06 15:02 
GeneralRe: Porting this to event-based? Pin
Nader Elshehabi25-Sep-06 15:31
Nader Elshehabi25-Sep-06 15:31 
GeneralRe: Porting this to event-based? Pin
Lord Kixdemp26-Sep-06 14:55
Lord Kixdemp26-Sep-06 14:55 
AnswerRe: Porting this to event-based? Pin
Christian Graus24-Sep-06 15:12
protectorChristian Graus24-Sep-06 15:12 
GeneralRe: Porting this to event-based? Pin
Lord Kixdemp24-Sep-06 15:17
Lord Kixdemp24-Sep-06 15:17 
GeneralRe: Porting this to event-based? Pin
Christian Graus24-Sep-06 15:29
protectorChristian Graus24-Sep-06 15:29 
GeneralRe: Porting this to event-based? Pin
Lord Kixdemp25-Sep-06 8:14
Lord Kixdemp25-Sep-06 8:14 
Questionadd column to dataset Pin
Mohammed Elkholy24-Sep-06 10:39
Mohammed Elkholy24-Sep-06 10:39 
AnswerRe: add column to dataset Pin
Nader Elshehabi24-Sep-06 12:08
Nader Elshehabi24-Sep-06 12:08 
Question[Message Deleted] Pin
code_wiz24-Sep-06 8:06
code_wiz24-Sep-06 8:06 
AnswerRe: extracting a message value from LParam in Message in WndProc(...) Pin
Christian Graus24-Sep-06 11:58
protectorChristian Graus24-Sep-06 11:58 
QuestionRe: extracting a message value from LParam in Message in WndProc(...) Pin
Nader Elshehabi24-Sep-06 12:04
Nader Elshehabi24-Sep-06 12:04 
QuestionProblem getting serial port to open Pin
NYTSX24-Sep-06 7:50
NYTSX24-Sep-06 7:50 
AnswerRe: Problem getting serial port to open Pin
Ed.Poore24-Sep-06 8:23
Ed.Poore24-Sep-06 8:23 
GeneralRe: Problem getting serial port to open Pin
NYTSX25-Sep-06 0:59
NYTSX25-Sep-06 0:59 
GeneralRe: Problem getting serial port to open Pin
NYTSX25-Sep-06 1:12
NYTSX25-Sep-06 1:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.