Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ambiguous identifiers error due to kind overloads, fixes #134 #155

Merged
merged 2 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 25 additions & 25 deletions src/raylib.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2528,27 +2528,27 @@ proc exportDataAsCode*(data: openArray[byte], fileName: string): bool =

type
ShaderV* = concept
proc kind(x: typedesc[Self]): ShaderUniformDataType

template kind*(x: typedesc[float32]): ShaderUniformDataType = Float
template kind*(x: typedesc[Vector2]): ShaderUniformDataType = Vec2
template kind*(x: typedesc[Vector3]): ShaderUniformDataType = Vec3
template kind*(x: typedesc[Vector4]): ShaderUniformDataType = Vec4
template kind*(x: typedesc[int32]): ShaderUniformDataType = Int
template kind*(x: typedesc[array[2, int32]]): ShaderUniformDataType = Ivec2
template kind*(x: typedesc[array[3, int32]]): ShaderUniformDataType = Ivec3
template kind*(x: typedesc[array[4, int32]]): ShaderUniformDataType = Ivec4
template kind*(x: typedesc[array[2, float32]]): ShaderUniformDataType = Vec2
template kind*(x: typedesc[array[3, float32]]): ShaderUniformDataType = Vec3
template kind*(x: typedesc[array[4, float32]]): ShaderUniformDataType = Vec4
proc shaderKind(x: typedesc[Self]): ShaderUniformDataType

template shaderKind*(x: typedesc[float32]): ShaderUniformDataType = Float
template shaderKind*(x: typedesc[Vector2]): ShaderUniformDataType = Vec2
template shaderKind*(x: typedesc[Vector3]): ShaderUniformDataType = Vec3
template shaderKind*(x: typedesc[Vector4]): ShaderUniformDataType = Vec4
template shaderKind*(x: typedesc[int32]): ShaderUniformDataType = Int
template shaderKind*(x: typedesc[array[2, int32]]): ShaderUniformDataType = Ivec2
template shaderKind*(x: typedesc[array[3, int32]]): ShaderUniformDataType = Ivec3
template shaderKind*(x: typedesc[array[4, int32]]): ShaderUniformDataType = Ivec4
template shaderKind*(x: typedesc[array[2, float32]]): ShaderUniformDataType = Vec2
template shaderKind*(x: typedesc[array[3, float32]]): ShaderUniformDataType = Vec3
template shaderKind*(x: typedesc[array[4, float32]]): ShaderUniformDataType = Vec4

proc setShaderValue*[T: ShaderV](shader: Shader, locIndex: ShaderLocation, value: T) =
## Set shader uniform value
setShaderValueImpl(shader, locIndex, addr value, kind(T))
setShaderValueImpl(shader, locIndex, addr value, shaderKind(T))

proc setShaderValueV*[T: ShaderV](shader: Shader, locIndex: ShaderLocation, value: openArray[T]) =
## Set shader uniform value vector
setShaderValueVImpl(shader, locIndex, cast[pointer](value), kind(T), value.len.int32)
setShaderValueVImpl(shader, locIndex, cast[pointer](value), shaderKind(T), value.len.int32)

proc loadModelAnimations*(fileName: string): RArray[ModelAnimation] =
## Load model animations from file
Expand Down Expand Up @@ -2622,9 +2622,9 @@ proc exportImageToMemory*(image: Image, fileType: string): RArray[uint8] =

type
Pixel* = concept
proc kind(x: typedesc[Self]): PixelFormat
proc pixelKind(x: typedesc[Self]): PixelFormat

template kind*(x: typedesc[Color]): PixelFormat = UncompressedR8g8b8a8
template pixelKind*(x: typedesc[Color]): PixelFormat = UncompressedR8g8b8a8

template toColorArray*(a: openArray[byte]): untyped =
## Note: that `a` should be properly formatted, with a byte representation that aligns
Expand All @@ -2636,10 +2636,10 @@ template toColorArray*(a: openArray[byte]): untyped =

proc loadTextureFromData*[T: Pixel](pixels: openArray[T], width: int32, height: int32): Texture =
## Load texture using pixels
assert getPixelDataSize(width, height, kind(T)) == pixels.len*sizeof(T),
assert getPixelDataSize(width, height, pixelKind(T)) == pixels.len*sizeof(T),
"Mismatch between expected and actual data size"
let image = Image(data: cast[pointer](pixels), width: width, height: height,
format: kind(T), mipmaps: 1).WeakImage
format: pixelKind(T), mipmaps: 1).WeakImage
result = loadTextureFromImageImpl(image.Image)
if not isTextureValid(result): raiseRaylibError("Failed to load Texture from buffer")

Expand All @@ -2665,27 +2665,27 @@ proc loadRenderTexture*(width: int32, height: int32): RenderTexture2D =

proc updateTexture*[T: Pixel](texture: Texture2D, pixels: openArray[T]) =
## Update GPU texture with new data
assert texture.format == kind(T), "Incompatible texture format"
assert texture.format == pixelKind(T), "Incompatible texture format"
assert getPixelDataSize(texture.width, texture.height, texture.format) == pixels.len*sizeof(T),
"Mismatch between expected and actual data size"
updateTextureImpl(texture, cast[pointer](pixels))

proc updateTexture*[T: Pixel](texture: Texture2D, rec: Rectangle, pixels: openArray[T]) =
## Update GPU texture rectangle with new data
assert texture.format == kind(T), "Incompatible texture format"
assert texture.format == pixelKind(T), "Incompatible texture format"
assert getPixelDataSize(rec.width.int32, rec.height.int32, texture.format) == pixels.len*sizeof(T),
"Mismatch between expected and actual data size"
updateTextureImpl(texture, rec, cast[pointer](pixels))

proc getPixelColor*[T: Pixel](pixel: T): Color =
## Get Color from a source pixel pointer of certain format
assert getPixelDataSize(1, 1, kind(T)) == sizeof(T), "Pixel size does not match expected format"
getPixelColorImpl(addr pixel, kind(T))
assert getPixelDataSize(1, 1, pixelKind(T)) == sizeof(T), "Pixel size does not match expected format"
getPixelColorImpl(addr pixel, pixelKind(T))

proc setPixelColor*[T: Pixel](pixel: var T, color: Color) =
## Set color formatted into destination pixel pointer
assert getPixelDataSize(1, 1, kind(T)) == sizeof(T), "Pixel size does not match expected format"
setPixelColorImpl(addr pixel, color, kind(T))
assert getPixelDataSize(1, 1, pixelKind(T)) == sizeof(T), "Pixel size does not match expected format"
setPixelColorImpl(addr pixel, color, pixelKind(T))

proc loadFontData*(fileData: openArray[uint8]; fontSize: int32; codepoints: openArray[int32];
`type`: FontType): RArray[GlyphInfo] =
Expand Down
2 changes: 2 additions & 0 deletions src/raylib/raudio.c
Original file line number Diff line number Diff line change
Expand Up @@ -1855,6 +1855,8 @@ void SeekMusicStream(Music music, float position)

ma_mutex_lock(&AUDIO.System.lock);
music.stream.buffer->framesProcessed = positionInFrames;
music.stream.buffer->isSubBufferProcessed[0] = true;
music.stream.buffer->isSubBufferProcessed[1] = true;
ma_mutex_unlock(&AUDIO.System.lock);
}

Expand Down
8 changes: 8 additions & 0 deletions src/raylib/raymath.h
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,14 @@ RMAPI float Vector2DotProduct(Vector2 v1, Vector2 v2)
return result;
}

// Calculate two vectors cross product
RMAPI float Vector2CrossProduct(Vector2 v1, Vector2 v2)
{
float result = (v1.x*v2.y - v1.y*v2.x);

return result;
}

// Calculate distance between two vectors
RMAPI float Vector2Distance(Vector2 v1, Vector2 v2)
{
Expand Down
6 changes: 3 additions & 3 deletions src/rmem.nim
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,6 @@ proc realloc*(x: var MemPool, p: pointer, newSize: Natural): pointer =
proc getFreeMemory*(x: MemPool): int {.inline.} =
result = x.capacity - x.occupied

const
DefaultAlignment = when sizeof(int) <= 4: 8 else: 16

type
FreeNode = object
next: ptr FreeNode
Expand Down Expand Up @@ -348,6 +345,9 @@ proc free*[T](x: var ObjPool[T], p: ptr T) =
node.next = x.head
x.head = node

const
DefaultAlignment = when sizeof(int) <= 4: 8 else: 16

type
BiStack* = object # Double-ended stack (aka Deque)
front, back: int
Expand Down
50 changes: 25 additions & 25 deletions tools/wrapper/snippets/raylib_funcs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -76,27 +76,27 @@ proc exportDataAsCode*(data: openArray[byte], fileName: string): bool =

type
ShaderV* = concept
proc kind(x: typedesc[Self]): ShaderUniformDataType

template kind*(x: typedesc[float32]): ShaderUniformDataType = Float
template kind*(x: typedesc[Vector2]): ShaderUniformDataType = Vec2
template kind*(x: typedesc[Vector3]): ShaderUniformDataType = Vec3
template kind*(x: typedesc[Vector4]): ShaderUniformDataType = Vec4
template kind*(x: typedesc[int32]): ShaderUniformDataType = Int
template kind*(x: typedesc[array[2, int32]]): ShaderUniformDataType = Ivec2
template kind*(x: typedesc[array[3, int32]]): ShaderUniformDataType = Ivec3
template kind*(x: typedesc[array[4, int32]]): ShaderUniformDataType = Ivec4
template kind*(x: typedesc[array[2, float32]]): ShaderUniformDataType = Vec2
template kind*(x: typedesc[array[3, float32]]): ShaderUniformDataType = Vec3
template kind*(x: typedesc[array[4, float32]]): ShaderUniformDataType = Vec4
proc shaderKind(x: typedesc[Self]): ShaderUniformDataType

template shaderKind*(x: typedesc[float32]): ShaderUniformDataType = Float
template shaderKind*(x: typedesc[Vector2]): ShaderUniformDataType = Vec2
template shaderKind*(x: typedesc[Vector3]): ShaderUniformDataType = Vec3
template shaderKind*(x: typedesc[Vector4]): ShaderUniformDataType = Vec4
template shaderKind*(x: typedesc[int32]): ShaderUniformDataType = Int
template shaderKind*(x: typedesc[array[2, int32]]): ShaderUniformDataType = Ivec2
template shaderKind*(x: typedesc[array[3, int32]]): ShaderUniformDataType = Ivec3
template shaderKind*(x: typedesc[array[4, int32]]): ShaderUniformDataType = Ivec4
template shaderKind*(x: typedesc[array[2, float32]]): ShaderUniformDataType = Vec2
template shaderKind*(x: typedesc[array[3, float32]]): ShaderUniformDataType = Vec3
template shaderKind*(x: typedesc[array[4, float32]]): ShaderUniformDataType = Vec4

proc setShaderValue*[T: ShaderV](shader: Shader, locIndex: ShaderLocation, value: T) =
## Set shader uniform value
setShaderValueImpl(shader, locIndex, addr value, kind(T))
setShaderValueImpl(shader, locIndex, addr value, shaderKind(T))

proc setShaderValueV*[T: ShaderV](shader: Shader, locIndex: ShaderLocation, value: openArray[T]) =
## Set shader uniform value vector
setShaderValueVImpl(shader, locIndex, cast[pointer](value), kind(T), value.len.int32)
setShaderValueVImpl(shader, locIndex, cast[pointer](value), shaderKind(T), value.len.int32)

proc loadModelAnimations*(fileName: string): RArray[ModelAnimation] =
## Load model animations from file
Expand Down Expand Up @@ -170,9 +170,9 @@ proc exportImageToMemory*(image: Image, fileType: string): RArray[uint8] =

type
Pixel* = concept
proc kind(x: typedesc[Self]): PixelFormat
proc pixelKind(x: typedesc[Self]): PixelFormat

template kind*(x: typedesc[Color]): PixelFormat = UncompressedR8g8b8a8
template pixelKind*(x: typedesc[Color]): PixelFormat = UncompressedR8g8b8a8

template toColorArray*(a: openArray[byte]): untyped =
## Note: that `a` should be properly formatted, with a byte representation that aligns
Expand All @@ -184,10 +184,10 @@ template toColorArray*(a: openArray[byte]): untyped =

proc loadTextureFromData*[T: Pixel](pixels: openArray[T], width: int32, height: int32): Texture =
## Load texture using pixels
assert getPixelDataSize(width, height, kind(T)) == pixels.len*sizeof(T),
assert getPixelDataSize(width, height, pixelKind(T)) == pixels.len*sizeof(T),
"Mismatch between expected and actual data size"
let image = Image(data: cast[pointer](pixels), width: width, height: height,
format: kind(T), mipmaps: 1).WeakImage
format: pixelKind(T), mipmaps: 1).WeakImage
result = loadTextureFromImageImpl(image.Image)
if not isTextureValid(result): raiseRaylibError("Failed to load Texture from buffer")

Expand All @@ -213,27 +213,27 @@ proc loadRenderTexture*(width: int32, height: int32): RenderTexture2D =

proc updateTexture*[T: Pixel](texture: Texture2D, pixels: openArray[T]) =
## Update GPU texture with new data
assert texture.format == kind(T), "Incompatible texture format"
assert texture.format == pixelKind(T), "Incompatible texture format"
assert getPixelDataSize(texture.width, texture.height, texture.format) == pixels.len*sizeof(T),
"Mismatch between expected and actual data size"
updateTextureImpl(texture, cast[pointer](pixels))

proc updateTexture*[T: Pixel](texture: Texture2D, rec: Rectangle, pixels: openArray[T]) =
## Update GPU texture rectangle with new data
assert texture.format == kind(T), "Incompatible texture format"
assert texture.format == pixelKind(T), "Incompatible texture format"
assert getPixelDataSize(rec.width.int32, rec.height.int32, texture.format) == pixels.len*sizeof(T),
"Mismatch between expected and actual data size"
updateTextureImpl(texture, rec, cast[pointer](pixels))

proc getPixelColor*[T: Pixel](pixel: T): Color =
## Get Color from a source pixel pointer of certain format
assert getPixelDataSize(1, 1, kind(T)) == sizeof(T), "Pixel size does not match expected format"
getPixelColorImpl(addr pixel, kind(T))
assert getPixelDataSize(1, 1, pixelKind(T)) == sizeof(T), "Pixel size does not match expected format"
getPixelColorImpl(addr pixel, pixelKind(T))

proc setPixelColor*[T: Pixel](pixel: var T, color: Color) =
## Set color formatted into destination pixel pointer
assert getPixelDataSize(1, 1, kind(T)) == sizeof(T), "Pixel size does not match expected format"
setPixelColorImpl(addr pixel, color, kind(T))
assert getPixelDataSize(1, 1, pixelKind(T)) == sizeof(T), "Pixel size does not match expected format"
setPixelColorImpl(addr pixel, color, pixelKind(T))

proc loadFontData*(fileData: openArray[uint8]; fontSize: int32; codepoints: openArray[int32];
`type`: FontType): RArray[GlyphInfo] =
Expand Down
2 changes: 1 addition & 1 deletion update_bindings.nims
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const
PkgDir = thisDir()
RaylibDir = PkgDir / "raylib"
RaylibGit = "https://github.com/raysan5/raylib.git"
RayLatestCommit = "26548c10620c4ae6937cf8b506c777a006b33c16"
RayLatestCommit = "0d39e7137b28980f05843bd505ef3e74d8772d03"
DocsDir = PkgDir / "docs"
ToolsDir = PkgDir / "tools"
ApiDir = ToolsDir / "wrapper/api"
Expand Down