Giter Site home page Giter Site logo

Comments (18)

raysan5 avatar raysan5 commented on May 22, 2024 1

I usually recommend setting a framerate (SetTargetFPS()) and using a framesCounter for animations but I understand that people can prefer time-based animations; a function is already available for that (it returns deltaTime). Not sure if that's enough for your needs...

float GetFrameTime(void); 

Right now, animation should be controlled by user, there is no specific mechanism in raylib. I understand you propose some mechanism similar to javascript:

window.setInterval(function, milliseconds);
window.setTimeout(function, milliseconds);

I need to think how to manage that internally...

from raylib.

raysan5 avatar raysan5 commented on May 22, 2024

Hi @kd7tck, that's a great idea.

Actually, that was my intention (kind of) with the introduced issues; related functions are listed in the issue description.

Maybe I could add more fine-grained detail to the description for better understanding and function implementation...

from raylib.

kd7tck avatar kd7tck commented on May 22, 2024

The GetTime() function, I would like to have it global so I can animate things in game with it. Could we make that function global and not static?
Perhaps there are better ways to animate, like creating hooked functions that can be called at certain time intervals from the raylib side. Something like: HookedCall(Function&, double interval);

from raylib.

kd7tck avatar kd7tck commented on May 22, 2024

I am assuming that the fixed interval animation type works because there is frame synchronization on the BeginDrawing or EndDrawing Call. Unfortunately I prefer frame rates that go as fast as possible and are not bound to any fixed value.

The following is code I am trying to optimize:

//returns true once complete
bool DrawAnimatedLine(Vector2 origin, Vector2 destination, double percentPerSec, Color color, double *percentComplete)
{
    if(*percentComplete >= 1.0){//what to do when already done
        DrawLineV(origin,destination,color);
        return true;
    }

    Vector3 a3 = {origin.x, origin.y, 0};
    Vector3 b3 = {destination.x, destination.y, 0};
    Vector3 c3 = VectorLerp(a3,b3,(float)*percentComplete);
    Vector2 c2 = {c3.x, c3.y};
    DrawLineV(origin,c2,color);

    //update then return
    *percentComplete += GetFrameTime() * percentPerSec;
    return false;
}

Any feedback or recommendations?

from raylib.

kd7tck avatar kd7tck commented on May 22, 2024

Another thing that I do not understand;
Why raymath is part of the lib, and not just a plain header file. You could have the math function definitions set to auto inline themselves. This would greatly increase game speeds.

I would be willing to volunteer my time to do this for you if you wished.

from raylib.

raysan5 avatar raysan5 commented on May 22, 2024

Hi @kd7tck

About animation management, your method is ok but I personally prefer to separate update logic from drawing. I would use an update function like:

Vector2 UpdateAnimLine(Vector2 initValue, Vector2 finalValue, int framesDuration, int framesCounter);

The return value is directly the current value. Some extra parameters could also be added as int framesDelay or int easingFunc. Actually, I got a single header file easings.h with multiple easing functions (based on Robert Penner's Easings). Don't know why I didn't uploaded it... I try to upload it tonight at home.

About raymath becoming a plain header file, it's a good idea, I just designed the other way to follow the standard C programming way. Inline functions where introduced in C99, so that's ok for raylib.

from raylib.

kd7tck avatar kd7tck commented on May 22, 2024

I just realized that the update rate is tied to the draw rate. So even if I get faster frame rates, it would simply speed up the animations. Is the version of GLFW you use threadable?

from raylib.

raysan5 avatar raysan5 commented on May 22, 2024

About GLFW3 threads: http://www.glfw.org/docs/latest/intro.html#thread_safety

from raylib.

kd7tck avatar kd7tck commented on May 22, 2024

I have a sample diff, (linked bellow) of the changes for the single raymath header file. Look it over and tell me if this is the direction it should go in.

https://drive.google.com/file/d/0B2jDwEP2AbatUUZ2TEVJeUtkU3c/view

from raylib.

raysan5 avatar raysan5 commented on May 22, 2024

Thanks very much for the effort @kd7tck! :)

I've been checking the diff and it's not exactly what I'm looking for; I want to avoid any additional #include in raylib.h. I always try to decouple modules as much as possible.

My idea for raymath.h was something similar to stb_image.h and just #include "raymath.h" in required modules (core, rlgl). Library itself should also be available to be used in standalone mode.

The problem here are the types definition, they must be in raylib.h but are also required in raymath.h; this should be managed using some #defines.

from raylib.

kd7tck avatar kd7tck commented on May 22, 2024

You mean like this

https://drive.google.com/file/d/0B2jDwEP2AbatUUZ2TEVJeUtkU3c/view?usp=sharing

from raylib.

raysan5 avatar raysan5 commented on May 22, 2024

Hi @kd7tck,

Despite being a bit difficult to see clearly all the changes in the .diff file, it seems you are in the right track, I like the solution.

Right now I'm investigating about the use of inline functions, not sure if that's the better option for all the functions, taking into consideration that some of them are quite big...

Here there are some references:

http://www.drdobbs.com/the-new-c-inline-functions/184401540
http://stackoverflow.com/questions/1932311/when-to-use-inline-function-and-when-not-to-use-it

from raylib.

kd7tck avatar kd7tck commented on May 22, 2024

The only downsides are when using 32 bit. 64 bit does not have page faults nearly as often, like 32 bit does. There should only be a performance boost, if you restrict the inlining to functions that are used every draw cycle. For me, math is one that always comes to mind.

from raylib.

kd7tck avatar kd7tck commented on May 22, 2024

Here is a more clear example not in diff.

https://drive.google.com/folderview?id=0B2jDwEP2AbatVDdrTTFRVG1GMVE&usp=sharing

from raylib.

raysan5 avatar raysan5 commented on May 22, 2024

Hi @kd7tck ,

Instead of defining for every function:

#ifdef RAYMATH_INLINE
static inline 
#else
static 
#endif

you can just define at the beginning:

#ifdef RAYMATH_INLINE
#define RMDEF static inline
#else
#define RMDEF static
#endif

and prepend functions with:

RMDEF Vector3 VectorAdd(Vector3 v1, Vector3 v2)

I really like stb_image.h single header style. I would follow that style defining:

#define RAYMATH_IMPLEMENTATION        // RAYMATH_DEFINE
#define RAYMATH_STANDALONE            // !RAYLIB_MATH_STRUCTS

Actually, maybe RAYMATH_IMPLEMENTATION could be skipped and just use RAYMATH_STANDALONE to include or not raymath structs (or use raylib structs instead).

Again, thank you very much for your time and effort and excuse me if I'm a bit picky... I really care about readable code and simplicity.

from raylib.

kd7tck avatar kd7tck commented on May 22, 2024

Not a problem. I went ahead and updated the code, look over my changes to the defines.

from raylib.

raysan5 avatar raysan5 commented on May 22, 2024

Hi @kd7tck !

I'm working on raylib v1.4 and I would like to include the raymath.h header-only file.

Please, could you make a pull-request with your current implementation? I will review it.

Thanks! :D

from raylib.

raysan5 avatar raysan5 commented on May 22, 2024

Changes merged and reviewed! 👍

from raylib.

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.