Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Z2Y committed Oct 2, 2020
1 parent a6b5d6f commit 30d44b6
Show file tree
Hide file tree
Showing 18 changed files with 9,330 additions and 5,123 deletions.
65 changes: 65 additions & 0 deletions bone/ArmatureDisplay.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package bone

import (
wrapper "dragonBones/dragonBones"
"log"
)

type ArmatureDisplayFace interface {
wrapper.IArmatureProxy
deleteIArmatureProxy()
IsIArmatureProxy()
}

type ArmatureDisplay struct {
Display
wrapper.IArmatureProxy
om *overwrittenMethodsOnArmatureDisplay
}

func (a *ArmatureDisplay) IsIArmatureProxy() {}

func (a *ArmatureDisplay) deleteIArmatureProxy() {
wrapper.DeleteDirectorIArmatureProxy(a.IArmatureProxy)
}

func NewArmatureDisplay() *ArmatureDisplay {
om := &overwrittenMethodsOnArmatureDisplay{}

face := wrapper.NewDirectorIArmatureProxy(om)
om.base = face

data := &ArmatureDisplay{IArmatureProxy: face, om: om}
boneObjectAdd(data.Swigcptr(), data)
return data
}

type overwrittenMethodsOnArmatureDisplay struct {
base wrapper.IArmatureProxy

armature wrapper.Armature
}

func (om *overwrittenMethodsOnArmatureDisplay) DbInit(armature wrapper.Armature) {
log.Println("DbInit")
om.armature = armature
}

func (om *overwrittenMethodsOnArmatureDisplay) DbClear() {
om.armature = nil
}

func (om *overwrittenMethodsOnArmatureDisplay) DbUpdate() {
log.Println("DbUpdate")
}

func (om *overwrittenMethodsOnArmatureDisplay) Dispose(bool) {
if om.armature != nil {
om.armature.Dispose()
om.armature = nil
}
}

func (om *overwrittenMethodsOnArmatureDisplay) HasDBEventListener(name string) bool {
return false
}
89 changes: 52 additions & 37 deletions bone/Display.go
Original file line number Diff line number Diff line change
@@ -1,62 +1,77 @@
package bone

import (
wrapper "dragonBones/dragonBones"
"log"
)
import "github.com/EngoEngine/gl"

type ArmatureDisplayFace interface {
wrapper.IArmatureProxy
deleteIArmatureProxy()
IsIArmatureProxy()
}
type IDisplay interface {
GetParent() IDisplay
SetParent(IDisplay)
AddChild(IDisplay)
RemoveChild(IDisplay)
GetChildren() []IDisplay
RemoveFromParent()

type ArmatureDisplay struct {
wrapper.IArmatureProxy
om *overwrittenMethodsOnArmatureDisplay
Texture() *gl.Texture
Width() float32
Height() float32
View() (float32, float32, float32, float32)
Close()
}

func (a *ArmatureDisplay) IsIArmatureProxy() {}
type Display struct {
Parent IDisplay
Children []IDisplay
}

func (a *ArmatureDisplay) deleteIArmatureProxy() {
wrapper.DeleteDirectorIArmatureProxy(a.IArmatureProxy)
func (d *Display) GetParent() IDisplay {
return d.Parent
}

func NewArmatureDisplay() *ArmatureDisplay {
om := &overwrittenMethodsOnArmatureDisplay{}
func (d *Display) SetParent(p IDisplay) {
d.Parent = p
}

face := wrapper.NewDirectorIArmatureProxy(om)
om.base = face
func (d *Display) AddChild(child IDisplay) {
child.SetParent(d)
d.Children = append(d.Children, child)
}

return &ArmatureDisplay{IArmatureProxy: face, om: om}
func (d *Display) RemoveChild(child IDisplay) {
delete := -1
for idx, c := range d.Children {
if c == child {
delete = idx
break
}
}
d.Children = append(d.Children[:delete], d.Children[delete+1:]...)
}

type overwrittenMethodsOnArmatureDisplay struct {
base wrapper.IArmatureProxy
func (d *Display) GetChildren() []IDisplay {
return d.Children
}

armature wrapper.Armature
func (d *Display) RemoveFromParent() {
if d.Parent != nil {
d.Parent.RemoveChild(d)
d.Parent = nil
}
}

func (om *overwrittenMethodsOnArmatureDisplay) DbInit(armature wrapper.Armature) {
log.Println("DbInit")
om.armature = armature
func (d *Display) Width() float32 {
return 0
}

func (om *overwrittenMethodsOnArmatureDisplay) DbClear() {
om.armature = nil
func (d *Display) Height() float32 {
return 0
}

func (om *overwrittenMethodsOnArmatureDisplay) DbUpdate() {
log.Println("DbUpdate")
func (d *Display) Texture() *gl.Texture {
return nil
}

func (om *overwrittenMethodsOnArmatureDisplay) Dispose(bool) {
if om.armature != nil {
om.armature.Dispose()
om.armature = nil
}
func (d *Display) View() (float32, float32, float32, float32) {
return 0, 0, 1, 1
}

func (om *overwrittenMethodsOnArmatureDisplay) HasDBEventListener(name string) bool {
return false
func (d *Display) Close() {
}
45 changes: 37 additions & 8 deletions bone/Factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@ import (
"io"
"io/ioutil"
"log"
"path/filepath"
"runtime"
"unsafe"
)

var (
Factory = NewFactory()
)

type DragonBoneFactoryFace interface {
wrapper.BaseFactory

Expand All @@ -21,8 +26,6 @@ type DragonBoneFactoryFace interface {

type DragonBoneFactory struct {
wrapper.BaseFactory

basePath string
}

func (s *DragonBoneFactory) deleteFactory() {
Expand All @@ -42,6 +45,10 @@ func NewFactory() *DragonBoneFactory {
return factory
}

func (factory *DragonBoneFactory) SetAssetPath(base string) {
factory.DirectorInterface().(*overwrittenMethodsOnFactory).basePath = base
}

func (factory *DragonBoneFactory) LoadDragonBonesData(reader io.Reader, name string, scale float32) (wrapper.DragonBonesData, error) {
bytes, err := ioutil.ReadAll(reader)

Expand All @@ -64,22 +71,43 @@ func (factory *DragonBoneFactory) LoadTextureAtlasData(reader io.Reader, name st
factory.ParseTextureAtlasData(string(bytes), uintptr(0), name, scale)
}

func (factory *DragonBoneFactory) BuildArmatureDisplay(args ...interface{}) wrapper.Armature {
return factory.BuildArmature(args...)
func (factory *DragonBoneFactory) BuildArmatureDisplay(args ...interface{}) *ArmatureDisplay {
armature := factory.BuildArmature(args...)
if armature.Swigcptr() != 0 {
factory.dragonBonesInstance().GetClock().Add(armature)
return boneObjectLookup(armature.GetDisplay()).(*ArmatureDisplay)
}
return nil
}

func (factory *DragonBoneFactory) dragonBonesInstance() wrapper.DragonBones {
return factory.DirectorInterface().(*overwrittenMethodsOnFactory).dragonBones
}

func (factory *DragonBoneFactory) Update(dt float32) {
factory.dragonBonesInstance().AdvanceTime(dt)
}

type overwrittenMethodsOnFactory struct {
base wrapper.BaseFactory

dragonBones wrapper.DragonBones
basePath string
}

func (om *overwrittenMethodsOnFactory) X_buildTextureAtlasData(data wrapper.TextureAtlasData, textureAtlas uintptr) wrapper.TextureAtlasData {
log.Println("build texture", data.Swigcptr(), textureAtlas)
if data.Swigcptr() == 0 {
return NewTextureAtlasData()
textureAtlasData := NewTextureAtlasData()
return textureAtlasData
} else {
log.Println(data.GetImagePath())
textureAtlasData := boneObjectLookup(data.Swigcptr()).(*TextureAtlasDataImpl)
texture, err := LoadTextureAtlas(filepath.Join(om.basePath, textureAtlasData.GetImagePath()))
if err != nil {
log.Println("TextureLoaded Error", err)
} else {
textureAtlasData.setRenderTexture(texture)
}
}
return data
}
Expand All @@ -88,14 +116,15 @@ func (om *overwrittenMethodsOnFactory) X_buildArmature(dataPackage wrapper.Build
log.Println("BuildArmature")
a := wrapper.BaseObjectBorrowArmatureObject()
armatureDisplay := NewArmatureDisplay()
boneObjectAdd(armatureDisplay.Swigcptr(), armatureDisplay)
a.Init(dataPackage.GetArmature(), armatureDisplay, armatureDisplay.Swigcptr(), om.dragonBones)
return a
}

func (om *overwrittenMethodsOnFactory) X_buildSlot(dataPackage wrapper.BuildArmaturePackage, slotData wrapper.DragonBones_SlotData, armature wrapper.Armature) wrapper.Slot {
slot := NewSlot()
slot.Init(slotData, armature, uintptr(0), uintptr(0))
sprite := NewSprite()
boneObjectAdd(uintptr(unsafe.Pointer(sprite)), sprite)
slot.Init(slotData, armature, uintptr(unsafe.Pointer(sprite)), uintptr(unsafe.Pointer(sprite)))
log.Println("BuildSlot", slot.Swigcptr())
return slot
}
67 changes: 67 additions & 0 deletions bone/Shader.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package bone

import (
"github.com/EngoEngine/ecs"
"github.com/EngoEngine/engo/common"
)

var (
DragonBoneHUDShader = NewDragonBoneShader(common.HUDShader)
DragonBoneDefaultShader = NewDragonBoneShader(common.DefaultShader)
)

type DragonBoneShader struct {
wrappedShader common.Shader
culling common.CullingShader
}

func NewDragonBoneShader(shader common.Shader) *DragonBoneShader {
if culling, ok := shader.(common.CullingShader); ok {
return &DragonBoneShader{wrappedShader: shader, culling: culling}
}
return &DragonBoneShader{wrappedShader: shader}
}

func (db *DragonBoneShader) PrepareCulling() {
if db.culling != nil {
db.culling.PrepareCulling()
}
}

func (db *DragonBoneShader) ShouldDraw(rc *common.RenderComponent, sc *common.SpaceComponent) bool {
// todo
return true
}

func (db *DragonBoneShader) Pre() {
db.wrappedShader.Pre()
}

func (db *DragonBoneShader) Draw(rc *common.RenderComponent, sc *common.SpaceComponent) {
db.DrawDisplay(rc.Drawable.(IDisplay), sc)
}

func (db *DragonBoneShader) DrawDisplay(iDisplay IDisplay, sc *common.SpaceComponent) {
children := iDisplay.GetChildren()
for _, subDisplay := range children {
db.DrawDisplay(subDisplay, sc)
}

switch display := iDisplay.(type) {
case *Sprite:
if display.RenderComponent.Drawable != nil {
db.wrappedShader.Draw(&display.RenderComponent, &display.SpaceComponent)
}
}
}

func (db *DragonBoneShader) Post() {
db.wrappedShader.Post()
}

func (db *DragonBoneShader) Setup(*ecs.World) error {
return nil
}

func (db *DragonBoneShader) SetCamera(cs *common.CameraSystem) {
}
Loading

0 comments on commit 30d44b6

Please sign in to comment.