mirror of
				https://github.com/Ukendio/jecs.git
				synced 2025-10-31 01:09:16 +00:00 
			
		
		
		
	Add start
This commit is contained in:
		
							parent
							
								
									e7bbf08713
								
							
						
					
					
						commit
						17415f27f3
					
				
					 7 changed files with 74 additions and 42 deletions
				
			
		
							
								
								
									
										
											BIN
										
									
								
								demo.rbxl
									
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								demo.rbxl
									
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							|  | @ -1,8 +1,5 @@ | |||
| local jecs = require(game:GetService("ReplicatedStorage").ecs) | ||||
| 
 | ||||
| local world = require(script.Parent.world) | ||||
| local sparse = ((world :: any) :: jecs.World).entityIndex.sparse | ||||
| type World = world.World | ||||
| type World = jecs.World | ||||
| 
 | ||||
| type Tracker<T> = { track: (world: World, fn: (changes: { | ||||
|         added: () -> () -> (number, T), | ||||
|  | @ -32,7 +29,8 @@ local function diff(a, b) | |||
|     return false | ||||
| end | ||||
| 
 | ||||
| local function ChangeTracker<T>(T: Entity<T>): Tracker<T> | ||||
| local function ChangeTracker<T>(world: World, T: Entity<T>): Tracker<T> | ||||
|     local sparse = world.entityIndex.sparse | ||||
|     local PreviousT = jecs.pair(jecs.Rest, T) | ||||
|     local add = {} | ||||
|     local added | ||||
|  |  | |||
|  | @ -3,12 +3,9 @@ local jecs = require(game:GetService("ReplicatedStorage").ecs) | |||
| local world = require(script.world) :: jecs.World | ||||
| export type World = jecs.World | ||||
| 
 | ||||
| local scheduler = require(script.scheduler) | ||||
| export type Scheduler = scheduler.Scheduler | ||||
| 
 | ||||
| local std = { | ||||
|     ChangeTracker = require(script.changetracker), | ||||
|     Scheduler = scheduler.new(world), | ||||
|     Scheduler = require(script.scheduler), | ||||
|     bt = require(script.bt), | ||||
|     collect = require(script.collect), | ||||
|     components = require(script.components), | ||||
|  | @ -19,6 +16,7 @@ local std = { | |||
|     world = world :: World, | ||||
|     pair = jecs.pair, | ||||
|     __ = jecs.w, | ||||
|     start = require(script.start) | ||||
| } | ||||
| 
 | ||||
| return std | ||||
|  |  | |||
|  | @ -10,9 +10,7 @@ type Entity<T=nil> = jecs.Entity<T> | |||
| 
 | ||||
| type System = { | ||||
|     callback: (world: World) -> (), | ||||
|     name: string, | ||||
|     rate: number?, | ||||
|     interval: number? | ||||
|     id: number, | ||||
| } | ||||
| 
 | ||||
| type Systems = { System } | ||||
|  | @ -71,9 +69,14 @@ do | |||
|     local system: System | ||||
|     local dt | ||||
|     local function run() | ||||
|         debug.profilebegin(system.name) | ||||
|         local id = system.id | ||||
|         local system_data = scheduler.system_data[id] | ||||
| 		if system_data.paused then return end | ||||
| 
 | ||||
| 		scheduler:mark_system_frame_start(id) | ||||
|         system.callback(dt) | ||||
|         debug.profileend() | ||||
|         scheduler:mark_system_frame_end(id) | ||||
| 
 | ||||
|     end | ||||
|     local function panic(str) | ||||
|         -- We don't want to interrupt the loop when we error | ||||
|  | @ -90,7 +93,25 @@ do | |||
| 
 | ||||
|                     debug.profilebegin(event_name) | ||||
|                     for _, sys in systems do | ||||
|                         scheduler:run(sys.id, sys.system, dt) | ||||
|                         system = sys | ||||
|                         local didNotYield, why = xpcall(function() | ||||
|                             for _ in run do end | ||||
|                         end, debug.traceback) | ||||
| 
 | ||||
|                         if didNotYield then | ||||
|             				continue | ||||
|              			end | ||||
| 
 | ||||
|              			if string.find(why, "thread is not yieldable") then | ||||
|             				panic("Not allowed to yield in the systems." | ||||
|                 				.. "\n" | ||||
|                 				.. "System: " | ||||
|                 				.. debug.info(system.callback, "n") | ||||
|                 				.. " has been ejected" | ||||
| 				            ) | ||||
|             				continue | ||||
|              			end | ||||
|              			panic(why) | ||||
|                     end | ||||
|                     debug.profileend() | ||||
|                 end | ||||
|  | @ -107,7 +128,7 @@ do | |||
|                     name = system.name, | ||||
|                     phase = phase_name | ||||
|                 }), | ||||
|                 system = system.callback | ||||
|                 callback = system.callback | ||||
|             }) | ||||
|         end | ||||
|         for after in world:query(Phase):with(pair(DependsOn, phase)) do | ||||
|  | @ -166,7 +187,6 @@ do | |||
|         end | ||||
| 
 | ||||
|         world:add(Heartbeat, Phase) | ||||
|         world:set(Heartbeat, Name) | ||||
|         world:set(Heartbeat, Event, RunService.Heartbeat) | ||||
| 
 | ||||
|         world:add(PreSimulation, Phase) | ||||
|  | @ -174,20 +194,20 @@ do | |||
| 
 | ||||
|         world:add(PreAnimation, Phase) | ||||
|         world:set(PreAnimation, Event, RunService.PreAnimation) | ||||
|         for name, component in components do | ||||
|             world:set(component, Name, name) | ||||
|         end | ||||
| 
 | ||||
|         jabby.public.updated = true | ||||
|         table.insert(jabby.public, { | ||||
|             class_name = "World", | ||||
|             name = "MyWorld", | ||||
|             world = world, | ||||
|             debug = Name, | ||||
|             entities = {} | ||||
|         }) | ||||
|         for name, component in components do | ||||
|             world:set(component, Name, name) | ||||
|             print(Name, name) | ||||
|         end | ||||
|         }   ) | ||||
| 
 | ||||
| 
 | ||||
|         jabby.public.updated = true | ||||
|         scheduler = jabby.scheduler.create("scheduler") | ||||
| 
 | ||||
|         table.insert(jabby.public, scheduler) | ||||
|  |  | |||
							
								
								
									
										31
									
								
								demo/src/ReplicatedStorage/std/start.luau
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								demo/src/ReplicatedStorage/std/start.luau
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,31 @@ | |||
| local RunService = game:GetService("RunService") | ||||
| local UserInputService = game:GetService("UserInputService") | ||||
| local ReplicatedStorage = game:GetService("ReplicatedStorage") | ||||
| local jabby = require(ReplicatedStorage.Packages.jabby) | ||||
| local Scheduler = require(ReplicatedStorage.std.scheduler) | ||||
| local world = require(ReplicatedStorage.std.world) | ||||
| 
 | ||||
| local function start(modules) | ||||
|     local scheduler = Scheduler.new(world) | ||||
|     for _, module in modules do | ||||
|         require(module)(scheduler) | ||||
|     end | ||||
|     local events = scheduler.collect.all() | ||||
|     scheduler.systems.begin(events) | ||||
|     if RunService:IsClient() then | ||||
|         local client = jabby.obtain_client() | ||||
|         local player = game:GetService("Players").LocalPlayer | ||||
|         local apps = player:WaitForChild("PlayerGui") | ||||
|         local dtor | ||||
|         UserInputService.InputBegan:Connect(function(input) | ||||
|             if input.KeyCode == Enum.KeyCode.F4 then | ||||
|                 if dtor then | ||||
|                     dtor() | ||||
|                 end | ||||
|                 dtor = client.spawn_app(client.apps.home) | ||||
|  			end | ||||
|         end ) | ||||
| 	end | ||||
| end | ||||
| 
 | ||||
| return start | ||||
|  | @ -1,11 +1,4 @@ | |||
| local ReplicatedStorage = game:GetService("ReplicatedStorage") | ||||
| local std = require(ReplicatedStorage.std) | ||||
| local components = std.components | ||||
| local world = std.world | ||||
| local start = require(ReplicatedStorage.std.start) | ||||
| 
 | ||||
| local scheduler = std.Scheduler | ||||
| for _, module in script.Parent.systems:GetChildren() do | ||||
|     require(module)(scheduler) | ||||
| end | ||||
| local events = scheduler.collect.all() | ||||
| scheduler.systems.begin(events) | ||||
| start(script.Parent:WaitForChild("systems"):GetChildren()) | ||||
|  |  | |||
|  | @ -1,12 +1,4 @@ | |||
| local ReplicatedStorage = game:GetService("ReplicatedStorage") | ||||
| local std = require(ReplicatedStorage.std) | ||||
| local scheduler = std.Scheduler | ||||
| for _, module in script.Parent:WaitForChild("systems"):GetChildren() do | ||||
|     require(module)(scheduler) | ||||
| end | ||||
| local events = scheduler.collect.all() | ||||
| local start = require(ReplicatedStorage.std.start) | ||||
| 
 | ||||
| scheduler.systems.begin(events) | ||||
| local jabby = require(ReplicatedStorage.Packages.jabby) | ||||
| local client = jabby.obtain_client() | ||||
| client.spawn_app(client.apps.home) | ||||
| start(script.Parent:WaitForChild("systems"):GetChildren()) | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue