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

Capi #5

Draft
wants to merge 31 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
9c6c14b
Add .vscode folder to .gitignore
kodeyeen Jul 3, 2024
9b178f6
Expose ComponentEntryPoint
kodeyeen Jul 3, 2024
21d7440
Add omp-capi as a submodule
kodeyeen Jul 4, 2024
c29cc59
Rewrite callbacks using capi
kodeyeen Jul 4, 2024
c7e8830
Changes for v1
kodeyeen Jul 4, 2024
eb4f942
Comment onPlayerEnterPlayerGangZone callback
kodeyeen Jul 5, 2024
5be814d
Remove C wrapper files. Will generate them from capi/apidocs/api.json
kodeyeen Jul 5, 2024
f5f26fd
Clean up
kodeyeen Jul 5, 2024
efd72f4
Generate C wrappers
kodeyeen Jul 5, 2024
24cbc3f
Rename cwrappers -> wrappers
kodeyeen Jul 5, 2024
3c9a64e
Rename cwrappers -> wrappers
kodeyeen Jul 5, 2024
c5182fe
Define ompapi
kodeyeen Jul 5, 2024
f7d1d7b
Define ompcapi in the header file as it will be initialized in Go in …
kodeyeen Jul 5, 2024
f0c4bfc
typedef for CAPIStringView struct (tmp)
kodeyeen Jul 5, 2024
74ff061
Changes for v1 (rename DefaultCheckpoint -> Checkpoint)
kodeyeen Jul 5, 2024
77a1af5
Regenerate wrappers
kodeyeen Jul 5, 2024
52d3523
Fix codegen
kodeyeen Jul 5, 2024
eec4550
typedef for ComponentVersion
kodeyeen Jul 5, 2024
e4e4327
Remove c.go
kodeyeen Jul 5, 2024
7a5beba
Rename ompcapi -> ompapi
kodeyeen Jul 5, 2024
d193577
Newline
kodeyeen Jul 5, 2024
d0b7a38
Fix function names with multiple underscores
kodeyeen Jul 5, 2024
91fa178
Rename Component -> Group
kodeyeen Jul 5, 2024
1dc674d
Rename CWRAPPERS_H -> WRAPPERS_H
kodeyeen Jul 5, 2024
300880f
Remove ompapi definition from wrappers.h
kodeyeen Jul 5, 2024
ba52f89
Rewrite actor methods using capi
kodeyeen Jul 6, 2024
a6da3e7
Add ID getter for Actor
kodeyeen Jul 6, 2024
5033948
ompapi as a struct not struct pointer
kodeyeen Jul 6, 2024
eba8d03
Rewrite textlabel methods using capi
kodeyeen Jul 10, 2024
86586b8
Rewrite dialogs using capi
kodeyeen Jul 10, 2024
b48a108
Change for v1
kodeyeen Jul 11, 2024
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,5 @@ go.work
.ionide

# End of https://www.toptal.com/developers/gitignore/api/visualstudiocode,go,c

.vscode/
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "capi"]
path = capi
url = https://github.com/openmultiplayer/omp-capi.git
79 changes: 0 additions & 79 deletions actor.cpp

This file was deleted.

120 changes: 72 additions & 48 deletions actor.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package omp

// #include "include/actor.h"
// #include <stdlib.h>
// #include "include/wrappers.h"
import "C"
import (
"errors"
"time"
"unsafe"
)

Expand All @@ -18,7 +20,8 @@ type Actor struct {
}

func NewActor(skin int, pos Vector3, angle float32) (*Actor, error) {
cActor := C.actor_create(C.int(skin), C.float(pos.X), C.float(pos.Y), C.float(pos.Z), C.float(angle))
var cID C.int
cActor := C.Actor_Create(C.int(skin), C.float(pos.X), C.float(pos.Y), C.float(pos.Z), C.float(angle), &cID)
if cActor == nil {
return nil, errors.New("actor limit was reached")
}
Expand All @@ -27,119 +30,140 @@ func NewActor(skin int, pos Vector3, angle float32) (*Actor, error) {
}

func FreeActor(actor *Actor) {
C.actor_release(actor.handle)
C.Actor_Destroy(actor.handle)
}

func (a *Actor) ID() int {
return int(C.Actor_GetID(a.handle))
}

func (a *Actor) SetSkin(skin int) {
C.actor_setSkin(a.handle, C.int(skin))
C.Actor_SetSkin(a.handle, C.int(skin))
}

func (a *Actor) Skin() int {
return int(C.actor_getSkin(a.handle))
return int(C.Actor_GetSkin(a.handle))
}

func (a *Actor) ApplyAnimation(anim Animation) {
cLib := newCString(anim.Lib)
defer freeCString(cLib)
cLib := C.CString(anim.Lib)
defer C.free(unsafe.Pointer(cLib))

cName := newCString(anim.Name)
defer freeCString(cName)
cName := C.CString(anim.Name)
defer C.free(unsafe.Pointer(cName))

C.actor_applyAnimation(
C.Actor_ApplyAnimation(
a.handle,
C.float(anim.Delta),
newCUchar(anim.Loop),
newCUchar(anim.LockX),
newCUchar(anim.LockY),
newCUchar(anim.Freeze),
C.uint(anim.Duration.Milliseconds()),
cLib,
cName,
cLib,
C.float(anim.Delta),
C.bool(anim.Loop),
C.bool(anim.LockX),
C.bool(anim.LockY),
C.bool(anim.Freeze),
C.int(anim.Duration.Milliseconds()),
)
}

func (a *Actor) Animation() Animation {
cAnim := C.actor_getAnimation(a.handle)
var (
cLib C.struct_CAPIStringView
cName C.struct_CAPIStringView
cDelta C.float
cLoop C.bool
cLockX C.bool
cLockY C.bool
cFreeze C.bool
cTime C.int
)

C.Actor_GetAnimation(a.handle, &cLib, &cName, &cDelta, &cLoop, &cLockX, &cLockY, &cFreeze, &cTime)

return Animation{
Lib: C.GoStringN(cAnim.lib.buf, C.int(cAnim.lib.length)),
Name: C.GoStringN(cAnim.name.buf, C.int(cAnim.name.length)),
Delta: float32(cAnim.delta),
Loop: cAnim.loop != 0,
LockX: cAnim.lockX != 0,
LockY: cAnim.lockY != 0,
Freeze: cAnim.freeze != 0,
Lib: C.GoStringN(cLib.data, C.int(cLib.len)),
Name: C.GoStringN(cName.data, C.int(cName.len)),
Delta: float32(cDelta),
Loop: bool(cLoop),
LockX: bool(cLockX),
LockY: bool(cLockY),
Freeze: bool(cFreeze),
Duration: time.Duration(cTime) * time.Millisecond,
}
}

func (a *Actor) ClearAnimations() {
C.actor_clearAnimations(a.handle)
C.Actor_ClearAnimations(a.handle)
}

func (a *Actor) SetHealth(health float32) {
C.actor_setHealth(a.handle, C.float(health))
C.Actor_SetHealth(a.handle, C.float(health))
}

func (a *Actor) Health() float32 {
return float32(C.actor_getHealth(a.handle))
return float32(C.Actor_GetHealth(a.handle))
}

func (a *Actor) MakeInvulnerable() {
C.actor_setInvulnerable(a.handle, 1)
C.Actor_SetInvulnerable(a.handle, true)
}

func (a *Actor) UnmakeInvulnerable() {
C.actor_setInvulnerable(a.handle, 0)
C.Actor_SetInvulnerable(a.handle, false)
}

func (a *Actor) IsInvulnerable() bool {
return C.actor_isInvulnerable(a.handle) != 0
return bool(C.Actor_IsInvulnerable(a.handle))
}

func (a *Actor) IsStreamedInFor(plr *Player) bool {
return C.actor_isStreamedInForPlayer(a.handle, plr.handle) != 0
func (a *Actor) IsStreamedInFor(player *Player) bool {
return bool(C.Actor_IsStreamedInFor(a.handle, player.handle))
}

func (a *Actor) SpawnData() ActorSpawnData {
data := C.actor_getSpawnData(a.handle)
var cPosX, cPosY, cPosZ, cAngle C.float
var cSkin C.int

C.Actor_GetSpawnInfo(a.handle, &cPosX, &cPosY, &cPosZ, &cAngle, &cSkin)

return ActorSpawnData{
Position: Vector3{
X: float32(data.position.x),
Y: float32(data.position.y),
Z: float32(data.position.z),
X: float32(cPosX),
Y: float32(cPosY),
Z: float32(cPosZ),
},
FacingAngle: float32(data.facingAngle),
Skin: int(data.skin),
FacingAngle: float32(cAngle),
Skin: int(cSkin),
}
}

func (a *Actor) SetPosition(pos Vector3) {
C.actor_setPosition(a.handle, C.float(pos.X), C.float(pos.Y), C.float(pos.Z))
C.Actor_SetPos(a.handle, C.float(pos.X), C.float(pos.Y), C.float(pos.Z))
}

func (a *Actor) Position() Vector3 {
cPos := C.actor_getPosition(a.handle)
var cPosX, cPosY, cPosZ C.float

C.Actor_GetPos(a.handle, &cPosX, &cPosY, &cPosZ)

return Vector3{
X: float32(cPos.x),
Y: float32(cPos.y),
Z: float32(cPos.z),
X: float32(cPosX),
Y: float32(cPosY),
Z: float32(cPosZ),
}
}

func (a *Actor) SetVirtualWorld(vw int) {
C.actor_setVirtualWorld(a.handle, C.int(vw))
C.Actor_SetVirtualWorld(a.handle, C.int(vw))
}

func (a *Actor) VirtualWorld() int {
return int(C.actor_getVirtualWorld(a.handle))
return int(C.Actor_GetVirtualWorld(a.handle))
}

func (a *Actor) SetFacingAngle(angle float32) {
C.actor_setFacingAngle(a.handle, C.float(angle))
C.Actor_SetFacingAngle(a.handle, C.float(angle))
}

func (a *Actor) FacingAngle() float32 {
return float32(C.actor_getFacingAngle(a.handle))
return float32(C.Actor_GetFacingAngle(a.handle))
}
28 changes: 0 additions & 28 deletions c.go

This file was deleted.

1 change: 1 addition & 0 deletions capi
Submodule capi added at 854a0c
Loading