ENIGMA Forums

Outsourcing saves money => Issues Help Desk => Topic started by: TheExDeus on November 25, 2010, 08:23:13 am

Title: extern double returns 0
Post by: TheExDeus on November 25, 2010, 08:23:13 am
Solved: No need to read this unless you're bored.

I am playing with some curves (sounds dirty doesn't it?) and I have a problem almost totally unrelated to that. For some eye candy I usually use cos/sin and current_time to get oscillation. I used current_time and it always returned 0, then I found out that actually current_time is not defined anywhere (and Enigma doesn't report non existing variables, they just assume 0, and that is bad (people don't suggest to use "Threat undefined variables as 0" for a reason)). Anyway, I went to implement it myself thinking it is easy. Found key_game_globals.h, and uncommented "extern double      current_time;". Then went into WINDOWSmain.cpp and modified a small part to this:
Code: [Select]
extern double fps, current_time;
namespace enigma {
  clock_t lc;
  void sleep_for_framerate(int rs)
  {
    clock_t nc = clock();
    int sdur = 1000/rs - 1 - (nc - lc)*1000 / CLOCKS_PER_SEC;
    if (sdur > 0)
    {
        Sleep(sdur);
        fps = room_speed;
    }
    else
    {
        fps = CLOCKS_PER_SEC / (nc - lc);
        if(fps > room_speed){ fps = room_speed; }
    }
    lc = nc;
    current_time = clock() / double(CLOCKS_PER_SEC) * 1000;
  }
}
So now current_time holds ms till the program launched. In GM it actually holds the number of ms the system has started, but whatever. Now whenever I use "extern double current_time;" in .cpp I can get that number and it works great. But the problem is that when I use string(current_time) in Enigma it just still returns 0. Did I miss a place to put it?
I also uncommented the line in GAME_GLOBALS.h to "double      current_time;".

edit: I did everything right. Just didn't occur to me to restart LGM (I know I need to do this when I update header files, but not when I update .cpp files).
Title: Re: extern double returns 0
Post by: Josh @ Dreamland on November 25, 2010, 09:26:50 am
Restarting LGM shouldn't really have fixed that. Your current_time actually doesn't behave like GM's at all; GM's (as you said) returns milliseconds since boot, but it is also an accessor. What I mean is, you can use current_time to time operations in a script.

I'll see about implementing that one... it won't be as easy to mimic in C++ as extern double current_time;. :P
Title: Re: extern double returns 0
Post by: TheExDeus on November 25, 2010, 10:02:01 am
Yes, I am aware that it is not the same. But it works for my applications, thou I could just use a regular variable I guess.
Anyway, I am working on Bezier curves and slopes. Inspired by this:
http://gmc.yoyogames.com/index.php?showtopic=491339
He also had made a very great example to showcase the beauty.
Here is how it looks now in Enigma:
http://www.host-a.net/u/harrikiri/curvesexample.zip (http://www.host-a.net/u/harrikiri/curvesexample.zip)
I haven't created any spline functions, just Bezier. When I get a good grasp on how splines work I will implement thous too. When everything's ready I will release the code.

Also, the number in the corner is the segment number. More segments mean smoother line, but of course, slower drawing. You can increase/decrease them with up and down arrows on your keyboard. Click to move it to the mouse.

edit: And btw, restarting LGM did fix it. I haven't added any new modifications. I changed everything I mentioned.
Title: Re: extern double returns 0
Post by: r9k on November 27, 2010, 12:01:29 pm
Very nice curves. Nice work.
Title: Re: extern double returns 0
Post by: TheExDeus on November 27, 2010, 03:00:52 pm
Thanks. I have create splines, but I think I use some very bad method. But that was the only method I could easily grasp. Thou that method allows making a spline with infinite points, so that's nice. Now I am thinking of some method to allow user to pass thous points. I can't use ds_lists as LSnK does (the creator of curves extension), because they are not implemented yet (at least I think so). I could use _begin, _add_point(x,y), and _end thou. So I am trying to do so.