-
Notifications
You must be signed in to change notification settings - Fork 16
Conversation
I don't know if you agree with the last change but I decided to produce distinct cint instead of enums. Reasons are the usual: duplicate values, enums with holes used as bitsets. The last straw for me was having to support |
If I'm not mistaken, there are a bunch of If we don't try to be fully backwards-compatible, are we okay with overloadable enums as discussed in #55? |
Saw latest changes, looks really great |
@planetis-m I found these functions which are not in the set of destructors in #60, do we include them as well or there are some problems?
Distinct types will have to also convert other function signatures which use these types though. And it is less maintainable regarding our automation feature of c2nim. Maybe there are some tricks we could use to avoid a lot of text replacement and somehow do it more smartly. |
proc drawTexturePoly*(texture: Texture2D, center: Vector2, points: openarray[Vector2], texcoords: openarray[Vector2], tint: Color) = | ||
## Draw a textured polygon | ||
drawTexturePolyPriv(texture, center, cast[ptr UncheckedArray[Vector2]](points), cast[ptr UncheckedArray[Vector2]](texcoords), points.len.int32, tint) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't really need to rename the original function to drawTexturePolyPriv
, it can have same name
proc loadFontData*(fileData: openarray[uint8], fontSize: int32, fontChars: openarray[int32], `type`: FontType): seq[GlyphInfo] = | ||
## Load font data for further use | ||
let data = loadFontDataPriv(cast[ptr UncheckedArray[uint8]](fileData), fileData.len.int32, | ||
fontSize, cast[ptr UncheckedArray[int32]](fontChars), fontChars.len.int32, `type`) | ||
result = newSeq[GlyphInfo](fontChars.len) | ||
copyMem(result[0].addr, data, fontChars.len * sizeof(GlyphInfo)) | ||
memFree(data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure we can allow ourself doing newSeq
because it does extra allocation. Allocations are generally considered slow and this here will allocate twice the amount of memory and do twice the number of calls to allocate.
As I understand it is also impossible to make a sequence without addition allocations because of GC. Also, what would be a use case for sequences which we want to modify? There are length checks already in raylib_fields.nim
. Here I assume we need sequences to dynamically modify them, but why? We should also take into considerations that operations on sequences will allocate memory uncontrollably which is sometimes undesirable for games.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's also a View
type. I'm not sure about the progress on this. But it looks like a good option here. We can create a custom container which implements toOpenArray
for each type as well as an option.
type GlyphInfoArray = object
len: int,
p: ptr UncheckedArray[GlyphInfo]
proc toOpenArray(obj: GlyphInfoArray) ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will do that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, great! Do you want to discuss these options on the specific examples? It could make sense to try several ways of doing this conversion before rewriting the whole file to conform to the one specific variant. There's at least View
and custom container options. But we want to minimize the amount of work we are going to do. And possibly automate it.
Regarding automation, it really seems that your version with generation from JSON is going to be better in terms of maintainability. But it's not entirely clear if this is the case.
|
@planetis-m I made an attempt at using destructors #72 |
Does raylib_fields.nim work now? There's a comment about |
They work, I used templates as this comment suggests https://forum.nim-lang.org/t/8871#57987 but for the [] proc the problem is still there, but it won't cause any issue. So it's good to go.
Not yet implemented but it's a good idea imo. |
On each type c2nim automatically adds |
Yes but now .bycopy would only be added in the .importc procs and that would allow to write a native Nim procedure using .importc types without any issue. |
No description provided.