Skip to content

Commit 983e73f

Browse files
authored
Merge pull request #184 from huyhoang160593/feature/cross_compile_working
update to raylib 5.5
2 parents 7554408 + bfc41a3 commit 983e73f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+21121
-11843
lines changed

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Release
33
on:
44
push:
55
tags:
6-
- 'v*'
6+
- "v*"
77
jobs:
88
create_release:
99
runs-on: ubuntu-latest
@@ -214,4 +214,4 @@ jobs:
214214
upload_url: ${{ needs.create_release.outputs.upload_url }}
215215
asset_path: ./build/Release/node-raylib.node
216216
asset_name: node-raylib-darwin-x64.node
217-
asset_content_type: application/octet-stream
217+
asset_content_type: application/octet-stream

CMakeLists.txt

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
include(FetchContent)
22

3-
cmake_minimum_required(VERSION 3.11)
3+
# 2025-02-15: based on https://github.com/raysan5/raylib/blob/master/src/external/glfw/CMakeLists.txt, make sure the CMake version are between 3.4 and 3.28 or the whole raylib lib will face fatal errors
4+
cmake_minimum_required(VERSION 3.4...3.28 FATAL_ERROR)
45
project (node-raylib
56
VERSION 0.10.0
67
DESCRIPTION "Node.js bindings for raylib"
@@ -11,33 +12,35 @@ if ( CMAKE_COMPILER_IS_GNUCC )
1112
set(CMAKE_C_FLAGS "-fPIC ${CMAKE_C_FLAGS} -Wno-unused-result")
1213
set(CMAKE_CXX_FLAGS "-Wall -Wextra")
1314
endif()
15+
# 2025-02-15: based on @link: https://learn.microsoft.com/en-us/cpp/build/reference/o-options-optimize-code?view=msvc-170. MSVC only accept O2 and don't have O3 optimization flag
1416
if ( MSVC )
1517
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /w")
18+
set(CMAKE_CXX_FLAGS_RELEASE "-O2")
19+
else()
20+
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
1621
endif()
1722

1823
if(NOT CMAKE_BUILD_TYPE)
1924
set(CMAKE_BUILD_TYPE Release)
2025
endif()
2126

2227
set(CMAKE_CXX_FLAGS_DEBUG "-g")
23-
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
2428

2529
# version doesn't seem to pick correct version
26-
#find_package(raylib 4.5 QUIET EXACT)
30+
#find_package(raylib 5.5 QUIET EXACT)
2731
if (NOT raylib_FOUND)
2832
include(FetchContent)
2933
FetchContent_Declare(
3034
raylib
3135
GIT_REPOSITORY https://github.com/raysan5/raylib.git
32-
GIT_TAG 4.5.0
36+
GIT_TAG 5.5
3337
GIT_SHALLOW TRUE
3438
)
3539
FetchContent_GetProperties(raylib)
3640
if (NOT raylib_POPULATED)
3741
set(FETCHCONTENT_QUIET NO)
38-
FetchContent_Populate(raylib)
42+
FetchContent_MakeAvailable(raylib)
3943
set(BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
40-
add_subdirectory(${raylib_SOURCE_DIR} ${raylib_BINARY_DIR})
4144
endif()
4245
endif()
4346

@@ -75,7 +78,7 @@ set_target_properties(${PROJECT_NAME} PROPERTIES
7578
SUFFIX ".node"
7679
)
7780

78-
target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_11)
81+
target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_20)
7982

8083
target_include_directories(${PROJECT_NAME} PUBLIC
8184
"${CMAKE_JS_INC}"

docs/API.md

Lines changed: 2005 additions & 681 deletions
Large diffs are not rendered by default.

drm/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66

77
const raylib = require('../src/generated/node-raylib-drm')
8-
const { format } = require('util')
8+
const { format } = require('node:util')
99

1010
// Constants
1111
raylib.MAX_GAMEPADS = 4

examples/audio/audio_module_playing.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
********************************************************************************************/
1212

13-
const r = require('raylib')
13+
const r = require('../../index.js')
1414

1515
const MAX_CIRCLES = 64
1616

examples/audio/audio_multichannel_sound.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
*
1212
********************************************************************************************/
1313

14-
const r = require('raylib')
15-
const { join } = require('path')
14+
const r = require('../../index.js')
15+
const { join } = require('node:path')
1616

1717
// Initialization
1818
// --------------------------------------------------------------------------------------

examples/audio/audio_music_stream.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
*
1010
********************************************************************************************/
1111

12-
const r = require('raylib')
13-
const { join } = require('path')
12+
const r = require('../../index.js')
13+
const { join } = require('node:path')
1414

1515
// Initialization
1616
// --------------------------------------------------------------------------------------

examples/audio/audio_raw_stream.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*
1313
********************************************************************************************/
1414

15-
const r = require('raylib')
15+
const r = require('../../index.js')
1616

1717
function memcpy (src, srcOffset, dst, dstOffset, length) {
1818
let i

examples/audio/audio_sound_loading.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
*
1010
********************************************************************************************/
1111

12-
const r = require('raylib')
13-
const { join } = require('path')
12+
const r = require('../../index.js')
13+
const { join } = require('node:path')
1414

1515
// Initialization
1616
// --------------------------------------------------------------------------------------

examples/core/core_2d_camera.js

Lines changed: 92 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,136 +1,158 @@
11
/*******************************************************************************************
2-
*
3-
* raylib [core] example - 2d camera
4-
*
5-
* This example has been created using raylib 1.5 (www.raylib.com)
6-
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
7-
*
8-
* Copyright (c) 2016 Ramon Santamaria (@raysan5)
9-
*
10-
********************************************************************************************/
2+
*
3+
* raylib [core] example - 2d camera
4+
*
5+
* This example has been created using raylib 1.5 (www.raylib.com)
6+
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
7+
*
8+
* Copyright (c) 2016 Ramon Santamaria (@raysan5)
9+
*
10+
********************************************************************************************/
1111

12-
const r = require('raylib')
12+
const r = require("../../index.js");
1313

14-
const MAX_BUILDINGS = 100
14+
const MAX_BUILDINGS = 100;
1515

1616
// Initialization
1717
// --------------------------------------------------------------------------------------
18-
const screenWidth = 800
19-
const screenHeight = 450
18+
const screenWidth = 800;
19+
const screenHeight = 450;
2020

21-
r.InitWindow(screenWidth, screenHeight, 'raylib [core] example - 2d camera')
21+
r.InitWindow(screenWidth, screenHeight, "raylib [core] example - 2d camera");
2222

23-
const player = r.Rectangle(400, 280, 40, 40)
24-
const buildings = []
25-
const buildColors = []
23+
const player = r.Rectangle(400, 280, 40, 40);
24+
const buildings = [];
25+
const buildColors = [];
2626

27-
let spacing = 0
27+
let spacing = 0;
2828

2929
for (let i = 0; i < MAX_BUILDINGS; i++) {
30-
const height = r.GetRandomValue(100, 800)
30+
const height = r.GetRandomValue(100, 800);
3131
const newBuilding = r.Rectangle(
3232
-6000 + spacing,
3333
screenHeight - 130 - height,
3434
r.GetRandomValue(50, 200),
3535
height
36-
)
37-
spacing += newBuilding.width
38-
buildings.push(newBuilding)
39-
buildColors.push(r.Color(r.GetRandomValue(200, 240), r.GetRandomValue(200, 240), r.GetRandomValue(200, 250), 255))
36+
);
37+
spacing += newBuilding.width;
38+
buildings.push(newBuilding);
39+
buildColors.push(
40+
r.Color(
41+
r.GetRandomValue(200, 240),
42+
r.GetRandomValue(200, 240),
43+
r.GetRandomValue(200, 250),
44+
255
45+
)
46+
);
4047
}
4148

4249
const camera = r.Camera2D(
4350
r.Vector2(screenWidth / 2, screenHeight / 2),
4451
r.Vector2(player.x + 20, player.y + 20),
45-
0, 1)
52+
0,
53+
1
54+
);
4655

47-
r.SetTargetFPS(60) // Set our game to run at 60 frames-per-second
56+
r.SetTargetFPS(60); // Set our game to run at 60 frames-per-second
4857
// --------------------------------------------------------------------------------------
4958

5059
// Main game loop
51-
while (!r.WindowShouldClose()) { // Detect window close button or ESC key
60+
while (!r.WindowShouldClose()) {
61+
// Detect window close button or ESC key
5262
// Update
5363
// ----------------------------------------------------------------------------------
5464
if (r.IsKeyDown(r.KEY_RIGHT)) {
55-
player.x += 2 // Player movement
56-
camera.offset.x -= 2 // Camera displacement with player movement
65+
player.x += 2; // Player movement
66+
camera.offset.x -= 2; // Camera displacement with player movement
5767
} else if (r.IsKeyDown(r.KEY_LEFT)) {
58-
player.x -= 2 // Player movement
59-
camera.offset.x += 2 // Camera displacement with player movement
68+
player.x -= 2; // Player movement
69+
camera.offset.x += 2; // Camera displacement with player movement
6070
}
6171

6272
// Camera target follows player
63-
camera.target = r.Vector2(player.x + 20, player.y + 20)
73+
camera.target = r.Vector2(player.x + 20, player.y + 20);
6474

6575
// Camera rotation controls
6676
if (r.IsKeyDown(r.KEY_A)) {
67-
camera.rotation--
77+
camera.rotation--;
6878
} else if (r.IsKeyDown(r.KEY_S)) {
69-
camera.rotation++
79+
camera.rotation++;
7080
}
7181

7282
// Limit camera rotation to 80 degrees (-40 to 40)
7383
if (camera.rotation > 40) {
74-
camera.rotation = 40
84+
camera.rotation = 40;
7585
} else if (camera.rotation < -40) {
76-
camera.rotation = -40
86+
camera.rotation = -40;
7787
}
7888

7989
// Camera zoom controls
80-
camera.zoom += r.GetMouseWheelMove() * 0.05
90+
camera.zoom += r.GetMouseWheelMove() * 0.05;
8191

82-
if (camera.zoom > 3) camera.zoom = 3
83-
else if (camera.zoom < 0.1) camera.zoom = 0.1
92+
if (camera.zoom > 3) camera.zoom = 3;
93+
else if (camera.zoom < 0.1) camera.zoom = 0.1;
8494

8595
// Camera reset (zoom and rotation)
8696
if (r.IsKeyPressed(r.KEY_R)) {
87-
camera.zoom = 1.0
88-
camera.rotation = 0
97+
camera.zoom = 1.0;
98+
camera.rotation = 0;
8999
}
90100
// ----------------------------------------------------------------------------------
91101

92102
// Draw
93103
// ----------------------------------------------------------------------------------
94-
r.BeginDrawing()
104+
r.BeginDrawing();
95105

96-
r.ClearBackground(r.RAYWHITE)
106+
r.ClearBackground(r.RAYWHITE);
97107

98-
r.BeginMode2D(camera)
108+
r.BeginMode2D(camera);
99109

100-
r.DrawRectangle(-6000, 320, 13000, 8000, r.DARKGRAY)
110+
r.DrawRectangle(-6000, 320, 13000, 8000, r.DARKGRAY);
101111

102112
for (let i = 0; i < MAX_BUILDINGS; i++) {
103-
r.DrawRectangleRec(buildings[i], buildColors[i])
113+
r.DrawRectangleRec(buildings[i], buildColors[i]);
104114
}
105115

106-
r.DrawRectangleRec(player, r.RED)
107-
108-
r.DrawLine(camera.target.x, -screenHeight * 10, camera.target.x, screenHeight * 10, r.GREEN)
109-
r.DrawLine(-screenWidth * 10, camera.target.y, screenWidth * 10, camera.target.y, r.GREEN)
110-
111-
r.EndMode2D()
112-
113-
r.DrawText('SCREEN AREA', 640, 10, 20, r.RED)
114-
115-
r.DrawRectangle(0, 0, screenWidth, 5, r.RED)
116-
r.DrawRectangle(0, 5, 5, screenHeight - 10, r.RED)
117-
r.DrawRectangle(screenWidth - 5, 5, 5, screenHeight - 10, r.RED)
118-
r.DrawRectangle(0, screenHeight - 5, screenWidth, 5, r.RED)
119-
120-
r.DrawRectangle(10, 10, 250, 113, r.Fade(r.SKYBLUE, 0.5))
121-
r.DrawRectangleLines(10, 10, 250, 113, r.BLUE)
122-
123-
r.DrawText('Free 2d camera controls:', 20, 20, 10, r.BLACK)
124-
r.DrawText('- Right/Left to move Offset', 40, 40, 10, r.DARKGRAY)
125-
r.DrawText('- Mouse Wheel to Zoom in-out', 40, 60, 10, r.DARKGRAY)
126-
r.DrawText('- A / S to Rotate', 40, 80, 10, r.DARKGRAY)
127-
r.DrawText('- R to reset Zoom and Rotation', 40, 100, 10, r.DARKGRAY)
128-
129-
r.EndDrawing()
116+
r.DrawRectangleRec(player, r.RED);
117+
118+
r.DrawLine(
119+
camera.target.x,
120+
-screenHeight * 10,
121+
camera.target.x,
122+
screenHeight * 10,
123+
r.GREEN
124+
);
125+
r.DrawLine(
126+
-screenWidth * 10,
127+
camera.target.y,
128+
screenWidth * 10,
129+
camera.target.y,
130+
r.GREEN
131+
);
132+
133+
r.EndMode2D();
134+
135+
r.DrawText("SCREEN AREA", 640, 10, 20, r.RED);
136+
137+
r.DrawRectangle(0, 0, screenWidth, 5, r.RED);
138+
r.DrawRectangle(0, 5, 5, screenHeight - 10, r.RED);
139+
r.DrawRectangle(screenWidth - 5, 5, 5, screenHeight - 10, r.RED);
140+
r.DrawRectangle(0, screenHeight - 5, screenWidth, 5, r.RED);
141+
142+
r.DrawRectangle(10, 10, 250, 113, r.Fade(r.SKYBLUE, 0.5));
143+
r.DrawRectangleLines(10, 10, 250, 113, r.BLUE);
144+
145+
r.DrawText("Free 2d camera controls:", 20, 20, 10, r.BLACK);
146+
r.DrawText("- Right/Left to move Offset", 40, 40, 10, r.DARKGRAY);
147+
r.DrawText("- Mouse Wheel to Zoom in-out", 40, 60, 10, r.DARKGRAY);
148+
r.DrawText("- A / S to Rotate", 40, 80, 10, r.DARKGRAY);
149+
r.DrawText("- R to reset Zoom and Rotation", 40, 100, 10, r.DARKGRAY);
150+
151+
r.EndDrawing();
130152
// ----------------------------------------------------------------------------------
131153
}
132154

133155
// De-Initialization
134156
// --------------------------------------------------------------------------------------
135-
r.CloseWindow() // Close window and OpenGL context
157+
r.CloseWindow(); // Close window and OpenGL context
136158
// --------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)