1
0
mirror of https://github.com/lxsang/Diya-API.git synced 2024-12-27 03:48:21 +01:00

refactory code

This commit is contained in:
Dany LE 2022-08-13 15:55:51 +02:00
parent 766ae23f8e
commit c1f2de2896
13 changed files with 81 additions and 56 deletions

View File

@ -30,11 +30,11 @@ Diya2DPrimShape >> draw [
self texture ifNotNil: [ self texture ifNotNil: [
self texture setup. self texture setup.
context texture0 setImage2D: self texture. context texture0 setImage2D: self texture.
context texture0 active. context texture0 active.
]. ].
context vao enableAttribute: 0. context vao enableAttribute: 0.
OpenGLVertexArray vertexAttributePointerIndex: 0 size:4 type: GL_FLOAT normalized: GL_FALSE stride: 16 pointer: nil . OpenGLVertexArray vertexAttributePointerIndex: 0 size:4 type: GL_FLOAT normalized: GL_FALSE stride: 16 pointer: nil.
context vbo data: GL_ARRAY_BUFFER data: vbuffer usage: GL_STATIC_DRAW. context vbo data: GL_ARRAY_BUFFER data: vbuffer usage: GL_DYNAMIC_DRAW.
OpenGL drawArrays: type first:0 count:((vbuffer size )>> 2 ). OpenGL drawArrays: type first:0 count:((vbuffer size )>> 2 ).
"reset value" "reset value"
self texture ifNotNil: [self texture drop.]. self texture ifNotNil: [self texture drop.].

View File

@ -20,7 +20,7 @@ DiyaApplicationLauncher >> bindGlobalEvent [
|pointer | |pointer |
pointer := root addNode: (DiyaCircle r: 10) at: 200@200. pointer := root addNode: (DiyaCircle r: 10) at: 200@200.
pointer styleName: #pointer. pointer styleName: #pointer.
root on: #keydown do:[:e| Transcript show: 'keydown...';cr. running := false.]. root on: #keydown do:[:e| self stdlog: 'keydown...'. running := false.].
root on: #quit do: [:e| running := false]. root on: #quit do: [:e| running := false].
root on: #(fingerdown fingermotion mousemotion) do:[:e| root on: #(fingerdown fingermotion mousemotion) do:[:e|
pointer position: e mapped worldPosition. pointer position: e mapped worldPosition.
@ -47,11 +47,16 @@ DiyaApplicationLauncher >> launch: app [
root empty. root empty.
]. ].
currapp := app uniqueInstance. currapp := app uniqueInstance.
currapp setup.
currapp root forceReload.
Transcript show: 'APPLICATION INIT'; cr.
self context assets: currapp am. self context assets: currapp am.
self appNode addNode: currapp root. [
self stdlog: 'Loading application'.
currapp root visibility: false.
currapp setup.
self appNode addNode: currapp root.
self process: true.
currapp root visibility: true.
self stdlog: 'Application LOADED'.
] fork.
] ]
{ #category : #initialization } { #category : #initialization }
@ -65,23 +70,22 @@ DiyaApplicationLauncher >> main [
root trigger: (DiyaEvent from: event mapped). root trigger: (DiyaEvent from: event mapped).
]. ].
currapp ifNotNil: [currapp main.]. currapp ifNotNil: [currapp main.].
"root render."
root stepDown. root stepDown.
self process. self process: false.
root render. root render.
] ]
{ #category : #initialization } { #category : #initialization }
DiyaApplicationLauncher >> process [ DiyaApplicationLauncher >> process: force [
|Q node maxProcessingTime| |Q node maxProcessingTime|
maxProcessingTime := 1000 / DiyaBoot maxFPS - 100. maxProcessingTime := (1000 / DiyaBoot maxFPS) asInteger >> 1.
Q := root processingQueue select:[:e| e visibility]. Q := root processingQueue.
Q ifEmpty:[^ self]. Q ifEmpty:[^ self].
[ [
node := Q removeFirst. node := Q removeFirst.
node process. node process.
root cleanDirtyNode: node. Q isNotEmpty and: (
Q isNotEmpty and: DiyaClock uniqueInstance lapDelta asMilliSeconds < maxProcessingTime (DiyaClock uniqueInstance lapDelta asMilliSeconds < maxProcessingTime) or: force)
] whileTrue ] whileTrue
] ]

View File

@ -13,11 +13,6 @@ DiyaBaseObject >> checkGLError: mark [
]. ].
] ]
{ #category : #accessing }
DiyaBaseObject >> logError: string [
self stderr nextPutAll: string; cr
]
{ #category : #asserting } { #category : #asserting }
DiyaBaseObject >> shouldNotBeCalled [ DiyaBaseObject >> shouldNotBeCalled [
^DiyaCoreAPIError signal: 'Should not be called' ^DiyaCoreAPIError signal: 'Should not be called'
@ -30,12 +25,19 @@ DiyaBaseObject >> stderr [
{ #category : #accessing } { #category : #accessing }
DiyaBaseObject >> stderror: string [ DiyaBaseObject >> stderror: string [
self stderr nextPutAll: string; nextPutAll: Character cr asString. self stderr
nextPutAll: DateAndTime now asString;
nextPutAll: ': ';
nextPutAll: string;
nextPutAll: Character cr asString.
] ]
{ #category : #accessing } { #category : #accessing }
DiyaBaseObject >> stdlog: string [ DiyaBaseObject >> stdlog: string [
self stdout nextPutAll: string; self stdout
nextPutAll: DateAndTime now asString;
nextPutAll: ': ';
nextPutAll: string;
nextPutAll: Character cr asString. nextPutAll: Character cr asString.
] ]

View File

@ -41,7 +41,6 @@ DiyaButton >> label [
{ #category : #accessing } { #category : #accessing }
DiyaButton >> process [ DiyaButton >> process [
rec extent: self extent. rec extent: self extent.
label position: 0@0.
label extent: self extent. label extent: self extent.
^true ^true
] ]

View File

@ -30,8 +30,6 @@ DiyaDefaultTheme >> defineLoadingBar [
}; };
define: #loadingProgress styles: { define: #loadingProgress styles: {
#bgColor -> Color white. #bgColor -> Color white.
#border -> 0.
#fontSize -> 18.
} }
] ]

View File

@ -14,7 +14,7 @@ DiyaExampleApp >> defineStyleSheet [
|fmgr style| |fmgr style|
fmgr := DiyaFontManager uniqueInstance. fmgr := DiyaFontManager uniqueInstance.
#(16 24) do:[:fontSize| #(16 24) do:[:fontSize|
Transcript show: 'Init font size ', fontSize asString, ' of ', fmgr defaultFamily; cr. self stdlog: 'Init font size ', fontSize asString, ' of ', fmgr defaultFamily.
style := fmgr style: fmgr defaultStyle from: fmgr defaultFamily. style := fmgr style: fmgr defaultStyle from: fmgr defaultFamily.
style textureOf: fontSize. style textureOf: fontSize.
]. ].
@ -85,11 +85,11 @@ DiyaExampleApp >> setup [
label styleName:#text_icon_1. label styleName:#text_icon_1.
label icon: 16rF254. label icon: 16rF254.
node1 := root addNode: (DiyaRectangle size:100@150 shader: DiyaExampleShader uniqueInstance) at: 300 @ 40. "node1 := root addNode: (DiyaRectangle size:100@150 shader: DiyaExampleShader uniqueInstance) at: 300 @ 40.
node1 rotation: 45. node1 rotation: 45.
node1 scale: 2.0@2.0. node1 scale: 2.0@2.0.
node1 on: #(mousebuttondown fingerdown) do:[:e| node1 on: #(mousebuttondown fingerdown) do:[:e|
label txt: 'RECT ', (node1 local: e mapped worldPosition) asIntegerPoint asString]. label txt: 'RECT ', (node1 local: e mapped worldPosition) asIntegerPoint asString]."
img := root addNode: (DiyaImageView from:'mrsang.png') at: 10 @ 400. img := root addNode: (DiyaImageView from:'mrsang.png') at: 10 @ 400.
img styleName: #image_view. img styleName: #image_view.
@ -120,11 +120,11 @@ DiyaExampleApp >> setup [
ell := root addNode: (DiyaEllipse rx:100 ry: 70) at: 120@300. ell := root addNode: (DiyaEllipse rx:100 ry: 70) at: 120@300.
ell scale: 1.2 @ 1.2. ell scale: 1.2 @ 1.2.
ell styleName: #ell_view. ell styleName: #ell_view.
ell rotation: 30. "ell rotation: 30."
ell textureNamed:'mrsang.png'. ell textureNamed:'mrsang.png'.
"ell addNode: (DiyaTimerNode timeout: 1000 / 6 do:[:n | ell addNode: (DiyaTimerNode timeout: 1000 / 6 do:[:n |
n parent rotation: n parent rotation + 10. n parent rotation: n parent rotation + 10.
] )". ] ).
ell on: #(mousebuttondown fingerdown) do:[:e| ell on: #(mousebuttondown fingerdown) do:[:e|
label txt: 'Ellipse clicked', (ell local:e mapped worldPosition) asIntegerPoint asString]. label txt: 'Ellipse clicked', (ell local:e mapped worldPosition) asIntegerPoint asString].
@ -156,6 +156,15 @@ DiyaExampleApp >> setup [
n parent percent: p. n parent percent: p.
] ). ] ).
Transcript show: 'Application setup';cr.
loading := root addNode: (DiyaLoadingBar new) at: 240@580.
loading extent: 200 @ 20.
loading addNode: (DiyaTimerNode timeout: 1000 do:[:n |
|p|
p := (n parent percent + 10).
p > 100 ifTrue:[ p := 0].
n parent percent: p.
] ).
^ root ^ root
] ]

View File

@ -74,7 +74,7 @@ DiyaFontManager >> loadFile: aFile [
index: i. index: i.
face newFaceFromFile: path index: i. face newFaceFromFile: path index: i.
face loadFields. face loadFields.
Transcript show: 'Loaded font face ', face styleName;cr. self stdlog: 'Loaded font face ', face styleName.
numfaces ifNil: [ numfaces := face numFaces ]. numfaces ifNil: [ numfaces := face numFaces ].
self loadFace: face. self loadFace: face.
i := i + 1. i := i + 1.

View File

@ -77,7 +77,7 @@ DiyaImageTex >> fromDisplayAs: assetName [
{ #category : #'instance creation' } { #category : #'instance creation' }
DiyaImageTex >> fromFile: aPath [ DiyaImageTex >> fromFile: aPath [
|surface| |surface|
Transcript show: 'Loading texture from ', aPath fullName;cr. self stdlog: 'Loading texture from ', aPath fullName.
data ifNotNil: [ data free ]. data ifNotNil: [ data free ].
name := aPath fullName. name := aPath fullName.
surface := self surfaceFromFile: aPath. surface := self surfaceFromFile: aPath.
@ -89,7 +89,7 @@ DiyaImageTex >> fromFile: aPath [
LibC memCopy: surface pixels getHandle to: data getHandle size: data size. LibC memCopy: surface pixels getHandle to: data getHandle size: data size.
SDL2 SDL2
freeSurface: surface. freeSurface: surface.
Transcript show: 'Loaded ', aPath fullName;cr. self stdlog: 'Loaded ', aPath fullName.
] ]
{ #category : #'instance creation' } { #category : #'instance creation' }

View File

@ -88,11 +88,16 @@ DiyaLine >> process [
self position: bbox origin. self position: bbox origin.
extent := bbox extent. extent := bbox extent.
bbox := (Rectangle origin: 0@0 corner: extent ). bbox := (Rectangle origin: 0@0 corner: extent ).
vbuffer
at: 1 put: 0.0;
at: 2 put: 0.0;
at: 3 put: 0.0;
at: 4 put: 0.0;
{ at: 5 put: extent x;
0.0. 0.0. 0.0. 0.0. at: 6 put: extent y;
extent x. extent y. 0.0. 0.0. at: 7 put: 0.0;
} doWithIndex: [:e :i| vbuffer at: i put: e]. at: 8 put: 0.0.
^true ^true
] ]

View File

@ -45,12 +45,8 @@ DiyaLoadingBar >> percent: anObject [
{ #category : #processing } { #category : #processing }
DiyaLoadingBar >> process [ DiyaLoadingBar >> process [
|border|
border := bar ? #border.
bar extent: self extent. bar extent: self extent.
progress position: border@border. progress extent: ((self percent) * (self extent x) / 100) @ (self extent y).
progress extent: ((self percent) * (self extent x) / 100 -( border << 1)) @ (self extent y - (border << 1)).
"label extent: self extent."
] ]
{ #category : #accessing } { #category : #accessing }

View File

@ -40,11 +40,25 @@ DiyaRectangle >> initialize [
DiyaRectangle >> process [ DiyaRectangle >> process [
|extent| |extent|
extent := self extent. extent := self extent.
{ vbuffer
0. 0. 0.0. 0.0. at: 1 put: 0.0;
0. extent y. 0.0. 1.0. at: 2 put: 0.0;
extent x. extent y. 1.0. 1.0. at: 3 put: 0.0;
extent x. 0. 1.0. 0.0. at: 4 put: 0.0;
} doWithIndex: [:e :i| vbuffer at: i put: e].
at: 5 put: 0.0;
at: 6 put: extent y;
at: 7 put: 0.0;
at: 8 put: 1.0;
at: 9 put: extent x;
at: 10 put: extent y;
at: 11 put: 1.0;
at: 12 put: 1.0;
at: 13 put: extent x;
at: 14 put: 0.0;
at: 15 put: 1.0;
at: 16 put: 0.0.
^true ^true
] ]

View File

@ -44,5 +44,5 @@ DiyaSingleton class >> uniqueInstance [
{ #category : #initialization } { #category : #initialization }
DiyaSingleton >> initialize [ DiyaSingleton >> initialize [
super initialize. super initialize.
Transcript show: 'Initialise unique instance of ', self className; cr. self stdlog: 'Initialise unique instance of ', self className.
] ]

View File

@ -54,9 +54,7 @@ ImageInitializer >> initializeImage [
do: [ retryList add: c ] ]. do: [ retryList add: c ] ].
retryList retryList
do: [ :c | do: [ :c |
Transcript self stdlog: 'CLASS: ' , c asString , ' is not initialized, retry'.
show: 'CLASS: ' , c asString , ' is not initialized';
cr.
c initialize ]. c initialize ].
DiyaSingleton resetAll. DiyaSingleton resetAll.
FFIMethodRegistry resetAll. FFIMethodRegistry resetAll.