Git Product home page Git Product logo

Comments (3)

satoshinm avatar satoshinm commented on August 17, 2024

Time of day is calculated by glfwGetTime() http://www.glfw.org/docs/latest/group__input.html#gaa6cf4e7a77158a3b8fd00328b1720a4a (which "measures time elapsed since GLFW was initialized"):

float time_of_day() {
    if (g->day_length <= 0) {
        return 0.5;
    }
    float t;
    t = glfwGetTime();
    t = t / g->day_length;
    t = t - (int)t;
    return t;
}

so at startup, it'll be near 0


Some tests:

  • glfwGetTime(): -7am
  • +g->day_length/4: -2am
  • +g->day_length/2: 4am
  • +g->day_length: 4pm
  • +g->day_length/1.5: 8am

Note future enhancement, would require changing how time works: #11 Add /time command to change/freeze time of day, nighttime/daytime

from netcraft.

satoshinm avatar satoshinm commented on August 17, 2024

glfwSetTime() to day_length/3 should set to about 8am (8 / 24 = 0.3'), works on native not emscripten, so maybe emscripten bug? library_glfw.js:

  glfwGetTime: function() {
    return GLFW.getTime() - GLFW.initialTime;
  },

  glfwSetTime: function(time) {
    GLFW.initialTime = GLFW.getTime() + time;
  },

GLFW.getTime() returns _emscripten_get_now() / 1000. Is glfwSetTime() wrong, why doesn't it set directly to the time parameter not + GLFW.getTime()? This is glfw3 time:

GLFWAPI double glfwGetTime(void)
{
    _GLFW_REQUIRE_INIT_OR_RETURN(0.0);
    return (double) (_glfwPlatformGetTimerValue() - _glfw.timer.offset) /
        _glfwPlatformGetTimerFrequency();
}

GLFWAPI void glfwSetTime(double time)
{
    _GLFW_REQUIRE_INIT();

    if (time != time || time < 0.0 || time > 18446744073.0)
    {
        _glfwInputError(GLFW_INVALID_VALUE, "Invalid time %f", time);
        return;
    }

    _glfw.timer.offset = _glfwPlatformGetTimerValue() -
        (uint64_t) (time * _glfwPlatformGetTimerFrequency());
}

Confirmed, fixing emscripten fixes it. Opened pull request: emscripten-core/emscripten#5304

from netcraft.

satoshinm avatar satoshinm commented on August 17, 2024

Patching in #194

from netcraft.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.