2021-12-18 02:02:16 +01:00
|
|
|
Class {
|
|
|
|
#name : #DiyaBoot,
|
2022-02-15 18:04:54 +01:00
|
|
|
#superclass : #DiyaSingleton,
|
2021-12-19 12:32:23 +01:00
|
|
|
#instVars : [
|
|
|
|
'window',
|
2021-12-20 01:14:35 +01:00
|
|
|
'context',
|
2022-02-15 18:04:54 +01:00
|
|
|
'display',
|
|
|
|
'clock'
|
2021-12-19 12:32:23 +01:00
|
|
|
],
|
|
|
|
#pools : [
|
2021-12-20 01:14:35 +01:00
|
|
|
'OpenGLConstants',
|
|
|
|
'OpenGLTypes',
|
2021-12-19 12:32:23 +01:00
|
|
|
'SDL2Constants',
|
|
|
|
'SDL2Types'
|
|
|
|
],
|
2021-12-19 16:15:10 +01:00
|
|
|
#category : #'Diya-Runtime'
|
2021-12-18 02:02:16 +01:00
|
|
|
}
|
|
|
|
|
2022-08-08 16:35:04 +02:00
|
|
|
{ #category : #'class initialization' }
|
|
|
|
DiyaBoot class >> initialize [
|
2022-08-14 18:33:19 +02:00
|
|
|
Smalltalk globals at: #DiyaDisplay put: nil.
|
|
|
|
Smalltalk globals at: #DiyaSystemClock put: nil.
|
|
|
|
Smalltalk globals at: #DiyaRenderer put: nil.
|
|
|
|
Smalltalk globals at: #DiyaSystemSettings put: nil.
|
2022-08-08 16:35:04 +02:00
|
|
|
]
|
|
|
|
|
2021-12-19 12:32:23 +01:00
|
|
|
{ #category : #'instance creation' }
|
2021-12-18 02:02:16 +01:00
|
|
|
DiyaBoot class >> startUp: status [
|
2021-12-18 22:49:03 +01:00
|
|
|
self startx.
|
2021-12-18 02:02:16 +01:00
|
|
|
]
|
|
|
|
|
2021-12-19 12:32:23 +01:00
|
|
|
{ #category : #'instance creation' }
|
2021-12-18 22:49:03 +01:00
|
|
|
DiyaBoot class >> startx [
|
2021-12-19 16:15:10 +01:00
|
|
|
self uniqueInstance run
|
2021-12-19 12:32:23 +01:00
|
|
|
]
|
|
|
|
|
2021-12-20 01:14:35 +01:00
|
|
|
{ #category : #events }
|
|
|
|
DiyaBoot >> createGLContext [
|
|
|
|
context := SDL2 glCreateContext: window.
|
2022-03-19 02:18:29 +01:00
|
|
|
context ifNil: [ ^DiyaCoreAPIError signal: SDL2 getErrorMessage ].
|
2021-12-20 01:14:35 +01:00
|
|
|
^context
|
|
|
|
|
|
|
|
]
|
|
|
|
|
2021-12-19 12:32:23 +01:00
|
|
|
{ #category : #events }
|
|
|
|
DiyaBoot >> createWindow [
|
2022-03-16 01:32:01 +01:00
|
|
|
SDL2
|
|
|
|
glSetAttribute: SDL_GL_MULTISAMPLEBUFFERS value: 1;
|
|
|
|
glSetAttribute: SDL_GL_MULTISAMPLESAMPLES value: 2.
|
|
|
|
|
|
|
|
OpenGL enable: GL_MULTISAMPLE.
|
|
|
|
|
2021-12-20 01:14:35 +01:00
|
|
|
window := SDL2 createWindow: 'Diya'
|
2021-12-19 12:32:23 +01:00
|
|
|
x: 0
|
|
|
|
y: 0
|
2021-12-19 16:15:10 +01:00
|
|
|
width: display w
|
|
|
|
height: display h
|
2021-12-20 01:14:35 +01:00
|
|
|
flags: SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL.
|
2022-03-19 02:18:29 +01:00
|
|
|
window ifNil: [ ^DiyaCoreAPIError signal: SDL2 getErrorMessage ].
|
2021-12-19 12:32:23 +01:00
|
|
|
"handle fullscreen: SDL_WINDOW_FULLSCREEN."
|
2022-03-04 20:28:38 +01:00
|
|
|
"SDL2 glSetAttribute: SDL_GL_CONTEXT_PROFILE_MASK value: SDL_GL_CONTEXT_PROFILE_ES.
|
|
|
|
SDL2 glSetAttribute: SDL_GL_CONTEXT_MAJOR_VERSION value: 2.
|
|
|
|
SDL2 glSetAttribute: SDL_GL_CONTEXT_MINOR_VERSION value: 0.
|
|
|
|
SDL2 glSetAttribute: SDL_GL_ACCELERATED_VISUAL value: 1."
|
|
|
|
"SDL2 glSetAttribute: SDL_GL_DOUBLEBUFFER value: 1.
|
|
|
|
SDL2 glSetAttribute: SDL_GL_DEPTH_SIZE value: 24."
|
|
|
|
|
2021-12-20 01:14:35 +01:00
|
|
|
^window
|
2021-12-19 12:32:23 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #events }
|
|
|
|
DiyaBoot >> init [
|
2021-12-19 22:17:29 +01:00
|
|
|
| status |
|
2022-03-04 20:28:38 +01:00
|
|
|
SDL2 setHint: 'SDL_RENDER_DRIVER' value: 'opengles2'.
|
2021-12-19 16:15:10 +01:00
|
|
|
status := SDL2 init: SDL_INIT_EVERYTHING.
|
2022-03-03 23:23:43 +01:00
|
|
|
status = 0
|
2022-03-19 02:18:29 +01:00
|
|
|
ifFalse: [ ^ DiyaCoreAPIError signal: SDL2 getErrorMessage ].
|
2021-12-19 22:17:29 +01:00
|
|
|
display := SDL_DisplayMode externalNew autoRelease.
|
|
|
|
SDL2 SDLGetCurrentDisplayMode: display from:0.
|
2022-03-21 18:03:15 +01:00
|
|
|
SDL2 showCursor: 0.
|
2022-08-14 18:13:23 +02:00
|
|
|
DiyaSingleton resetAll.
|
2022-08-10 19:55:49 +02:00
|
|
|
Smalltalk globals at: #Display ifAbsentPut:display.
|
|
|
|
Smalltalk globals at: #DiyaDisplay put:display.
|
2022-08-14 18:13:23 +02:00
|
|
|
Smalltalk globals at: #DiyaSystemSettings put: DiyaSettings uniqueInstance.
|
|
|
|
Smalltalk globals at: #DiyaSystemClock put: DiyaClock uniqueInstance.
|
2021-12-19 12:32:23 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #events }
|
|
|
|
DiyaBoot >> initialize [
|
2021-12-19 22:41:21 +01:00
|
|
|
display := nil.
|
|
|
|
window := nil.
|
2021-12-20 01:14:35 +01:00
|
|
|
context := nil.
|
2022-08-14 18:13:23 +02:00
|
|
|
clock := DiyaSystemClock.
|
2021-12-19 12:32:23 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #events }
|
2021-12-19 16:15:10 +01:00
|
|
|
DiyaBoot >> render [
|
2022-08-15 12:28:09 +02:00
|
|
|
|launcher event|
|
|
|
|
event := SDL_Event new.
|
2022-03-21 18:03:15 +01:00
|
|
|
launcher := DiyaApplicationLauncher uniqueInstance.
|
2022-08-14 16:52:22 +02:00
|
|
|
"Init the Open GL view port and enable 2D texture"
|
|
|
|
OpenGL viewportX: 0 Y:0 W: display w H: display h.
|
|
|
|
OpenGL enable: GL_TEXTURE_2D.
|
2022-08-16 00:59:35 +02:00
|
|
|
launcher target: DiyaRenderer root.
|
2022-08-15 12:28:09 +02:00
|
|
|
launcher onloaded: [self stdlog: 'Launcher loaded'].
|
2022-03-21 18:03:15 +01:00
|
|
|
[ launcher running ] whileTrue: [
|
2022-08-14 18:13:23 +02:00
|
|
|
DiyaSystemClock tick.
|
2022-08-15 12:28:09 +02:00
|
|
|
[(SDL2 pollEvent: event) > 0] whileTrue: [
|
|
|
|
DiyaRenderer root trigger: (DiyaEvent from: event mapped).
|
|
|
|
].
|
2022-08-14 18:13:23 +02:00
|
|
|
DiyaRenderer render.
|
2022-08-12 16:37:53 +02:00
|
|
|
SDL2 delay:
|
|
|
|
(0 max:
|
2022-08-14 22:49:36 +02:00
|
|
|
(1000/ DiyaSystemSettings maxFPS) asInteger - (DiyaSystemClock lapDelta)).
|
2022-02-13 17:15:23 +01:00
|
|
|
].
|
|
|
|
]
|
|
|
|
|
2021-12-19 16:15:10 +01:00
|
|
|
{ #category : #events }
|
|
|
|
DiyaBoot >> run [
|
2022-05-23 12:26:46 +02:00
|
|
|
|envar arr|
|
|
|
|
envar := Smalltalk getenv:'DIYA_RES'.
|
|
|
|
arr := nil.
|
|
|
|
envar ifNotNil: [
|
|
|
|
arr := (envar splitOn: 'x') collect: [ :e| e asInteger ] .
|
|
|
|
arr size = 2 ifFalse:[
|
|
|
|
arr := nil.
|
|
|
|
]
|
|
|
|
].
|
|
|
|
arr
|
|
|
|
ifNil: [
|
|
|
|
self init.
|
|
|
|
self startx.
|
|
|
|
]
|
|
|
|
ifNotNil: [
|
|
|
|
self run: (arr at:1) @ (arr at: 2)
|
|
|
|
]
|
2021-12-19 20:03:54 +01:00
|
|
|
]
|
|
|
|
|
2021-12-19 22:17:29 +01:00
|
|
|
{ #category : #running }
|
2021-12-19 20:03:54 +01:00
|
|
|
DiyaBoot >> run: screenSize [
|
2021-12-19 22:17:29 +01:00
|
|
|
self run: screenSize app: nil
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #running }
|
|
|
|
DiyaBoot >> run: screenSize app: application [
|
2021-12-19 22:52:35 +01:00
|
|
|
"
|
|
|
|
this function should be used only in
|
|
|
|
SDK environment, in real embeded system
|
|
|
|
it is always the #run command that is executed
|
|
|
|
automatically.
|
|
|
|
"
|
2021-12-20 01:14:35 +01:00
|
|
|
OpenGLTypes initialize.
|
|
|
|
OpenGLConstants initialize.
|
2021-12-19 20:03:54 +01:00
|
|
|
self init.
|
|
|
|
display w: screenSize x.
|
|
|
|
display h: screenSize y.
|
2021-12-19 22:52:35 +01:00
|
|
|
self startx.
|
|
|
|
self class reset.
|
2022-02-15 18:04:54 +01:00
|
|
|
DiyaClock reset.
|
|
|
|
DiyaRendererContext reset.
|
2021-12-19 22:52:35 +01:00
|
|
|
Smalltalk garbageCollect.
|
2021-12-19 20:03:54 +01:00
|
|
|
]
|
|
|
|
|
2021-12-19 22:17:29 +01:00
|
|
|
{ #category : #logging }
|
|
|
|
DiyaBoot >> showSystemInfo [
|
2021-12-19 22:41:21 +01:00
|
|
|
|stream numdriver rinfo|
|
|
|
|
stream := (String new: 255) writeStream.
|
2021-12-19 22:17:29 +01:00
|
|
|
stream nextPutAll:'System: ';
|
|
|
|
nextPutAll:(Smalltalk globals at: #CODENAME ifAbsent:['']);
|
|
|
|
nextPutAll: '-v';
|
|
|
|
nextPutAll:(Smalltalk globals at: #VERSION ifAbsent: ['']);cr.
|
|
|
|
numdriver := SDL2 SDLGetNumVideoDrivers.
|
|
|
|
stream nextPutAll: 'Supported video dirvers:'.
|
|
|
|
0 to: numdriver -1 do: [ :i |
|
|
|
|
stream nextPutAll: (SDL2 SDLGetVideoDriver: i); nextPutAll: ' '.
|
|
|
|
].
|
|
|
|
stream cr.
|
|
|
|
stream nextPutAll: 'Current selected video driver: ';
|
|
|
|
nextPutAll:(SDL2 SDLGetCurrentVideoDriver);cr.
|
|
|
|
numdriver := SDL2 SDLGetNumRenderDrivers.
|
|
|
|
stream nextPutAll: 'SDL_RENDER_DRIVER available:'.
|
|
|
|
rinfo := SDL_RendererInfo externalNew autoRelease.
|
|
|
|
0 to: numdriver - 1 do:[:i|
|
|
|
|
SDL2 SDLGetRendererDriverInfo: rinfo from: i.
|
|
|
|
stream nextPutAll: rinfo name readString; nextPutAll:' '.
|
|
|
|
].
|
|
|
|
stream cr.
|
2022-08-08 16:35:04 +02:00
|
|
|
stream nextPutAll: DiyaDisplay asString; cr.
|
2022-08-10 19:55:49 +02:00
|
|
|
stream cr.
|
2021-12-19 22:41:21 +01:00
|
|
|
self stdout nextPutAll: stream contents
|
2021-12-19 22:17:29 +01:00
|
|
|
|
|
|
|
]
|
|
|
|
|
2021-12-19 20:03:54 +01:00
|
|
|
{ #category : #events }
|
|
|
|
DiyaBoot >> startx [
|
2022-03-19 02:18:29 +01:00
|
|
|
display ifNil: [ ^DiyaCoreAPIError signal: 'Please run #init before this method' ].
|
2021-12-20 01:14:35 +01:00
|
|
|
self createWindow.
|
|
|
|
self createGLContext.
|
2022-03-15 19:11:19 +01:00
|
|
|
"SDL2 glMakeCurrent: window context: context."
|
2021-12-19 22:17:29 +01:00
|
|
|
self showSystemInfo.
|
2022-03-15 19:11:19 +01:00
|
|
|
DiyaRendererContext
|
2022-08-10 19:55:49 +02:00
|
|
|
uniqueInstance
|
|
|
|
display: display;
|
|
|
|
window: window;
|
|
|
|
useProjection: OrthoProjectionMatrix.
|
2022-08-14 18:13:23 +02:00
|
|
|
Smalltalk globals at: #DiyaRenderer put: DiyaRendererContext uniqueInstance.
|
2022-03-02 20:11:01 +01:00
|
|
|
self render.
|
2021-12-20 01:14:35 +01:00
|
|
|
context delete.
|
2021-12-19 16:15:10 +01:00
|
|
|
window destroy.
|
2022-03-21 18:03:15 +01:00
|
|
|
DiyaSingleton resetAll.
|
2021-12-19 16:15:10 +01:00
|
|
|
SDL2 quit.
|
|
|
|
]
|