1
0
mirror of https://github.com/lxsang/Diya-API.git synced 2024-12-26 11:28:22 +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 setup.
context texture0 setImage2D: self texture.
context texture0 active.
context texture0 active.
].
context vao enableAttribute: 0.
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.
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_DYNAMIC_DRAW.
OpenGL drawArrays: type first:0 count:((vbuffer size )>> 2 ).
"reset value"
self texture ifNotNil: [self texture drop.].

View File

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

View File

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

View File

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

View File

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

View File

@ -14,7 +14,7 @@ DiyaExampleApp >> defineStyleSheet [
|fmgr style|
fmgr := DiyaFontManager uniqueInstance.
#(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 textureOf: fontSize.
].
@ -85,11 +85,11 @@ DiyaExampleApp >> setup [
label styleName:#text_icon_1.
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 scale: 2.0@2.0.
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 styleName: #image_view.
@ -120,11 +120,11 @@ DiyaExampleApp >> setup [
ell := root addNode: (DiyaEllipse rx:100 ry: 70) at: 120@300.
ell scale: 1.2 @ 1.2.
ell styleName: #ell_view.
ell rotation: 30.
"ell rotation: 30."
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.
] )".
] ).
ell on: #(mousebuttondown fingerdown) do:[:e|
label txt: 'Ellipse clicked', (ell local:e mapped worldPosition) asIntegerPoint asString].
@ -156,6 +156,15 @@ DiyaExampleApp >> setup [
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
]

View File

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

View File

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

View File

@ -88,11 +88,16 @@ DiyaLine >> process [
self position: bbox origin.
extent := bbox 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;
{
0.0. 0.0. 0.0. 0.0.
extent x. extent y. 0.0. 0.0.
} doWithIndex: [:e :i| vbuffer at: i put: e].
at: 5 put: extent x;
at: 6 put: extent y;
at: 7 put: 0.0;
at: 8 put: 0.0.
^true
]

View File

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

View File

@ -40,11 +40,25 @@ DiyaRectangle >> initialize [
DiyaRectangle >> process [
|extent|
extent := self extent.
{
0. 0. 0.0. 0.0.
0. extent y. 0.0. 1.0.
extent x. extent y. 1.0. 1.0.
extent x. 0. 1.0. 0.0.
} doWithIndex: [:e :i| vbuffer at: i put: e].
vbuffer
at: 1 put: 0.0;
at: 2 put: 0.0;
at: 3 put: 0.0;
at: 4 put: 0.0;
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
]

View File

@ -44,5 +44,5 @@ DiyaSingleton class >> uniqueInstance [
{ #category : #initialization }
DiyaSingleton >> 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 ] ].
retryList
do: [ :c |
Transcript
show: 'CLASS: ' , c asString , ' is not initialized';
cr.
self stdlog: 'CLASS: ' , c asString , ' is not initialized, retry'.
c initialize ].
DiyaSingleton resetAll.
FFIMethodRegistry resetAll.