Skip to content

Commit 808d00b

Browse files
Added limitations
1 parent e7741b2 commit 808d00b

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

MAPPING.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ This is a one to one mapping of each raylib function.
7070
### Misc. functions
7171
| C API | PHP API | Comment |
7272
|-------|---------|---------|
73-
| void ShowLogo(void); | TODO ||
74-
| void SetConfigFlags(unsigned char flags); | TODO ||
73+
| void SetConfigFlags(unsigned char flags); | raylib\setConfigFlags(int flags) ||
7574
| void SetTraceLog(unsigned char types); | TODO ||
7675
| void TraceLog(int logType, const char *text, ...); | TODO ||
7776
| void TakeScreenshot(const char *fileName); | TODO ||
@@ -197,13 +196,13 @@ This is a one to one mapping of each raylib function.
197196
#### Basic shapes collision detection functions
198197
| C API | PHP API | Comment |
199198
|-------|---------|---------|
200-
| bool CheckCollisionRecs(Rectangle rec1, Rectangle rec2); | TODO ||
201-
| bool CheckCollisionCircles(Vector2 center1, float radius1, Vector2 center2, float radius2); | TODO ||
202-
| bool CheckCollisionCircleRec(Vector2 center, float radius, Rectangle rec); | TODO ||
203-
| Rectangle GetCollisionRec(Rectangle rec1, Rectangle rec2); | TODO ||
204-
| bool CheckCollisionPointRec(Vector2 point, Rectangle rec); | TODO ||
205-
| bool CheckCollisionPointCircle(Vector2 point, Vector2 center, float radius); | TODO ||
206-
| bool CheckCollisionPointTriangle(Vector2 point, Vector2 p1, Vector2 p2, Vector2 p3); | TODO ||
199+
| bool CheckCollisionRecs(Rectangle rec1, Rectangle rec2); | raylib\Collision\checkRecs(Rectangle $rec1, Rectangle $rec2) ||
200+
| bool CheckCollisionCircles(Vector2 center1, float radius1, Vector2 center2, float radius2); | raylib\Collision\checkCircles(Vector2 center1, float radius1, Vector2 center2, float radius2) ||
201+
| bool CheckCollisionCircleRec(Vector2 center, float radius, Rectangle rec); | raylib\Collision\checkCircleRec(Vector2 center, float radius, Rectangle rec) ||
202+
| Rectangle GetCollisionRec(Rectangle rec1, Rectangle rec2); | raylib\Collision\getRec(Rectangle rec1, Rectangle rec2) ||
203+
| bool CheckCollisionPointRec(Vector2 point, Rectangle rec); | raylib\Collision\checkPointRec(Vector2 point, Rectangle rec) ||
204+
| bool CheckCollisionPointCircle(Vector2 point, Vector2 center, float radius); | raylib\Collision\checkPointCircle(Vector2 point, Vector2 center, float radius) ||
205+
| bool CheckCollisionPointTriangle(Vector2 point, Vector2 p1, Vector2 p2, Vector2 p3); | raylib\Collision\checkPointTriangle(Vector2 point, Vector2 p1, Vector2 p2, Vector2 p3) ||
207206

208207
## Texture Loading and Drawing Functions (Module: textures)
209208

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,14 @@ RayLib is a library designed for procedural code. All functions live in a global
7373

7474
For example instead of calling `CheckCollisionPointTriangle()`, in PHP you'd call `raylib\Collision::checkPointTriangle()`. That static class method could technically live as a scoped function instead for example `raylib\Collision\checkPointTriangle` however this could become make importing far more tedious.
7575

76+
If this becomes a bigger problem, I can create a procedural API compatibility later to better align to RayLib's C-API.
77+
7678
## API Limitation
7779

78-
The PHP C-API has one glaring limitation and that is I cannot provide read AND write to class properties. For example, in RayLib you can call `rec->x += 1`, but in PHP you'll need to use getters and setters `rec->setX(rec->getX() + 1)`. Now this may change as there might be a way to support this but I think until PHP has true support for getters and setters as properties, rather than a magic catch all, I want to avoid this. By using properties, I need to maintain copies of every in two places, so it will add memory for little gain.
80+
The PHP RayLib implementation has two glaring limitations.
81+
82+
- All object properties must use **getters** and **setters**. At this time I am not aware of a way to have RayLib structs mirror into PHP object properties. So instead of `$vec->x += 1;` you must instead use `$vec->setX($vec->getX() + 1)`. I know it's a pain but even if there was a way to allow this, I may would have to keep two copies. PHP does have **magic** get and set functions that look to be available through the C-API so if that true then I might be able to introduce this later.
83+
- All RayLib object assignment i.e `$player->position = $position` will **not copy** the variable but instead **link** the property. So if you want to copy the data instead, you need to use PHP's clone feature `clone` i.e `$player->position = clone $position`.
7984

8085
## How To Build PHP Extension
8186

0 commit comments

Comments
 (0)