RobLoach / node-raylib

Node.js bindings for Raylib
https://robloach.github.io/node-raylib/
Other
256 stars 20 forks source link

WIP: raylib5 #180

Open konsumer opened 1 year ago

konsumer commented 1 year ago

Raylib5 was released. This branch documents the effort to upgrade.

Currently this fails to build. These are missing:

konsumer commented 1 year ago

Updating @raylib/api to latest seems to fix errors with actual raylib, but then I see other errors with raygui. We may have to split these or work on getting raygui working.

konsumer commented 2 weeks ago

On mac M1 (Sonoma 14.6.1 (23G93)) I think issue is something in node-raylib.cc. It's a bit hard to tell because it buries the build-error (it seems to select ninja, and I always have that prob with ninja, since I am dyslexic and it strips colors) but I searched for error, and I see these 2:

/Users/konsumer/Desktop/node-raylib/src/generated/node-raylib.cc:319:6: error: non-constant-expression cannot be narrowed from type 'uintptr_t' (aka 'unsigned long') to 'char' in initializer list [-Wc++11-narrowing]
  319 |      pointerFromValue(info, index + 4)
      |      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/konsumer/Desktop/node-raylib/src/generated/node-raylib.cc:319:6: note: insert an explicit cast to silence this issue
  319 |      pointerFromValue(info, index + 4)
      |      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |      static_cast<char>(               )
/Users/konsumer/Desktop/node-raylib/src/generated/node-raylib.cc:395:6: error: non-constant-expression cannot be narrowed from type 'uintptr_t' (aka 'unsigned long') to 'int' in initializer list [-Wc++11-narrowing]
  395 |      pointerFromValue(info, index + 2)
      |      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/konsumer/Desktop/node-raylib/src/generated/node-raylib.cc:395:6: note: insert an explicit cast to silence this issue
  395 |      pointerFromValue(info, index + 2)
      |      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |      static_cast<int>(                )

looks like uintptr_t (64 bit) is being crammed into 8bit char var.

In both cases, it appears to be usage of pointerFromValue:

inline ModelAnimation ModelAnimationFromValue(const Napi::CallbackInfo& info, int index) {
  return {
     intFromValue(info, index + 0),
     intFromValue(info, index + 1),
     (BoneInfo *) pointerFromValue(info, index + 2),
     (Transform **) pointerFromValue(info, index + 3),

     // HERE
     pointerFromValue(info, index + 4)
  };
}

inline AutomationEvent AutomationEventFromValue(const Napi::CallbackInfo& info, int index) {
  return {
     unsignedintFromValue(info, index + 0),
     unsignedintFromValue(info, index + 1),

     // HERE
     pointerFromValue(info, index + 2)
  };
}

In other uses of these, they have type-prefixes (to set what kind of pointer it is) so that might be the prob.

These are the 2 type-conversions:

// ModelAnimation
typedef struct ModelAnimation {
    int boneCount;          // Number of bones
    int frameCount;         // Number of animation frames
    BoneInfo *bones;        // Bones information (skeleton)
    Transform **framePoses; // Poses array by frame
    char name[32];          // Animation name
} ModelAnimation;

// Automation event
typedef struct AutomationEvent {
    unsigned int frame;             // Event frame
    unsigned int type;              // Event type (AutomationEventType)
    int params[4];                  // Event parameters (if required)
} AutomationEvent;

I tried to manually fix on first one, to try to match it to other calls of pointerFromValue:

inline ModelAnimation ModelAnimationFromValue(const Napi::CallbackInfo& info, int index) {
  return {
     intFromValue(info, index + 0),
     intFromValue(info, index + 1),
     (BoneInfo *) pointerFromValue(info, index + 2),
     (Transform **) pointerFromValue(info, index + 3),
     (char*)pointerFromValue(info, index + 4)
  };
}

which caused another error:

/Users/konsumer/Desktop/node-raylib/src/generated/node-raylib.cc:319:6: error: cannot initialize an array element of type 'char' with an rvalue of type 'char *'
  319 |      (char*)pointerFromValue(info, index + 4)
      |      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

so I am not sure how to resolve.

konsumer commented 1 week ago

I started working on simpler bindings that stay in C, and improve the build a bit, here. I think with enough type-helpers, it could improve & simplify things overall.