https://drfreckles42.itch.io/youre-the-os
My GUI:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<application>
<window id="mywindow" title="YouAreTheOS">
<vgroup>
<vgroup id="MainGroup" hide="false">
<hgroup>
<rectangle/>
<choice id="Difficulty">
<item>Easy</item>
<item>Normal</item>
<item>Hard</item>
</choice>
<rectangle/>
<button id="play">Play</button>
<rectangle/>
</hgroup>
<vgroup>
<hline/>
<button id="score">HighScore</button>
<rectangle/>
</vgroup>
</vgroup>
<vgroup id="Game" hide="true">
<!--CPU-Slots-->
<hgroup id="cpuslots">
<button id="Core1" height="64" width="64">Core1</button>
<button id="Core2" height="64" width="64">Core2</button>
<button id="Core3" height="64" width="64">Core3</button>
<button id="Core4" height="64" width="64">Core4</button>
</hgroup>
<!--Tasks-->
<scrollgroup id="tasks" horiz="true">
<rectangle/>
</scrollgroup>
<button id="Return" hide="true">Return</button>
<rectangle/>
</vgroup>
<vgroup id="HighScore" hide="true">
<rectangle/>
<choice id="ScoreDifficulty">
<item>Easy</item>
<item>Normal</item>
<item>Hard</item>
</choice>
<rectangle/>
<listview>
<column title="Player">
<item>Entry 1</item>
<item>Entry 2</item>
<item>Entry 3</item>
</column>
<column title="Score">
<item>Entry 1</item>
<item>Entry 2</item>
<item>Entry 3</item>
</column>
</listview>
<rectangle/>
<button id="ok">OK</button>
</vgroup>
<!--Status-->
<statusbar>
<item id="first">Welcome to my application</item>
<item id="second"/>
<item id="third"/>
</statusbar>
</vgroup>
</window>
</application>
Code: Select all
@REQUIRE "RapaGUI"
@APPTITLE "YouAreTheOS"
@APPVERSION "$VER: YouAreTheOS 1.0 (02.12.23)"
@APPCOPYRIGHT "Copyright ©2023, Kai Stegemann"
@APPAUTHOR "Kai Stegemann"
@APPDESCRIPTION "Small Game to educate task scheduling"
Global intervaltiming = 950
Global corecount = 4
Global tasklist = CreateList()
function p_TaskToPool(id)
moai.DoMethod("tasks", "initchange")
moai.DoMethod("tasks", "append", id)
moai.DoMethod("tasks", "exitchange", false)
EndFunction
function p_TaskFromPool(id)
moai.DoMethod("tasks", "initchange")
moai.DoMethod("tasks", "remove", id)
moai.DoMethod("tasks", "exitchange", false)
EndFunction
Function p_CreateTask()
DebugPrint("p_CreateTask")
Local id = RndStrong(#INTEGER,65536)
id = ToString(id)
DebugPrint("ID: "..id)
Local xml$ = "<button id=\""..id.."\" height=\"64\" width=\"64\">"..id.."</button>"
moai.CreateObject(xml$, "mywindow")
p_TaskToPool(id)
InsertItem(tasklist,id)
EndFunction
Function p_InspectCore(id)
DebugPrint("p_InspectCore")
Local text$ = moai.get(id,"text")
If(StartsWith(text$, "Core"))
;Core is already empty
Return()
Else
;give task to pool
p_TaskToPool(text$)
;rename Core
moai.set(id,"text",id)
EndIf()
EndFunction
Function p_FillCoreWithTask(taskid)
DebugPrint("p_FillCoreWithTask")
DebugPrint(taskid)
Local coreid = 0
;find available core
For Local i = 1 To corecount
Local moaid = "Core"..i
Local text$ = moai.get(moaid,"text")
If(StartsWith(text$,"Core"))
;Core is available
;place task here
moai.set(moaid,"text",taskid)
;remove task from pool
p_TaskFromPool(taskid)
;end loop
Break()
EndIf()
Next
EndFunction
Function p_RedrawTasks()
;age taks in pool
;proceed tasks in core
Return()
EndFunction
Function p_EventFunc(msg)
ForEach(msg, DebugPrint)
Switch msg.ID
Case "play":
moai.set("MainGroup","hide",true)
moai.set("HighScore","hide",true)
moai.set("Game","hide",false)
moai.set("first","text","CurrentScore")
moai.set("second","text","0")
moai.set("third","text","0")
SetInterval(1,p_CreateTask,intervaltiming)
SetInterval(2,p_RedrawTasks,40)
Case "ok":
moai.set("MainGroup","hide",false)
moai.set("HighScore","hide",true)
moai.set("Game","hide",true)
Case "score":
moai.set("HighScore","hide",false)
moai.set("MainGroup","hide",true)
moai.set("Game","hide",true)
Case "Core1":
p_InspectCore(msg.id)
Case "Core2":
p_InspectCore(msg.id)
Case "Core3":
p_InspectCore(msg.id)
Case "Core4":
p_InspectCore(msg.id)
Default:
;place given id to available cpu slot
p_FillCoreWithTask(msg.id)
EndSwitch
EndFunction
InstallEventHandler({RapaGUI = p_EventFunc})
moai.CreateApp(FileToString("YouAreTheOS.xml"))
Repeat
WaitEvent
Forever
The tasks are buttons. Is there a way to attach the state of the task to a button? Some kind of Traffic light, or background colour?
The current project freezes after some tasks are created.
The placement of the waiting tasks feels dirty. How can infinite tasks be organized to eat up less space?