mirror of
				https://github.com/Ukendio/jecs.git
				synced 2025-11-01 09:39:18 +00:00 
			
		
		
		
	Modify example
This commit is contained in:
		
							parent
							
								
									44534b7c81
								
							
						
					
					
						commit
						1937529dcb
					
				
					 2 changed files with 21 additions and 15 deletions
				
			
		|  | @ -9,15 +9,23 @@ local cts = require(std.components) | ||||||
| local Model = cts.Model | local Model = cts.Model | ||||||
| local Transform = cts.Transform | local Transform = cts.Transform | ||||||
| 
 | 
 | ||||||
| local moving_models = world:query(Transform, Model):cached() | local moved_models = world:query(Model, Transform):cached() | ||||||
|  | local updated_models = {} | ||||||
|  | local i = 0 | ||||||
|  | local function processed(n) | ||||||
|  | 	i += 1 | ||||||
|  | 	if i > n then | ||||||
|  | 		i = 0 | ||||||
|  | 		return true | ||||||
|  | 	end | ||||||
|  | 	return false | ||||||
|  | end | ||||||
|  | 
 | ||||||
| local function move(dt: number) | local function move(dt: number) | ||||||
| 	for _, transform, model in moving_models do | 	for entity, model in moved_models do | ||||||
| 		local cf = transform.new | 		if updated_models[entity] then | ||||||
| 		if cf ~= transform.old then | 			updated_models[entity] = nil | ||||||
| 			local part = model.PrimaryPart :: BasePart | 			model.PrimaryPart.CFrame = transform | ||||||
| 			local origo = part.CFrame |  | ||||||
| 			part.CFrame = origo:Lerp(cf, 1) |  | ||||||
| 			transform.old = cf |  | ||||||
| 		end | 		end | ||||||
| 	end | 	end | ||||||
| end | end | ||||||
|  | @ -25,11 +33,8 @@ end | ||||||
| local function syncTransforms() | local function syncTransforms() | ||||||
| 	for _, id, cf in blink.UpdateTransform.Iter() do | 	for _, id, cf in blink.UpdateTransform.Iter() do | ||||||
| 		local e = ref("server-" .. tostring(id)) | 		local e = ref("server-" .. tostring(id)) | ||||||
| 		local transform = world:get(e, Transform) | 		world:set(e, Transform, cf) | ||||||
| 		if not transform then | 		moved_models[e] = true | ||||||
| 			continue |  | ||||||
| 		end |  | ||||||
| 		transform.new = cf |  | ||||||
| 	end | 	end | ||||||
| end | end | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -28,6 +28,7 @@ local removed = world | ||||||
| 	:without(Position) | 	:without(Position) | ||||||
| 	:cached() | 	:cached() | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
| local e1 = named(world.entity, "e1") | local e1 = named(world.entity, "e1") | ||||||
| world:set(e1, Position, vector.create(10, 20, 30)) | world:set(e1, Position, vector.create(10, 20, 30)) | ||||||
| local e2 = named(world.entity, "e2") | local e2 = named(world.entity, "e2") | ||||||
|  | @ -39,7 +40,7 @@ end | ||||||
| 
 | 
 | ||||||
| world:set(e1, Position, vector.create(999, 999, 1998)) | world:set(e1, Position, vector.create(999, 999, 1998)) | ||||||
| 
 | 
 | ||||||
| for e, new, old in changed do | for _, archetype in changed:archetypes() do | ||||||
| 	if new ~= old then | 	if new ~= old then | ||||||
| 		print(`{name(e)}'s Position changed from \{{old.x}, {old.y}, {old.z}\} to \{{new.x}, {new.y}, {new.z}\}`) | 		print(`{name(e)}'s Position changed from \{{old.x}, {old.y}, {old.z}\} to \{{new.x}, {new.y}, {new.z}\}`) | ||||||
| 		world:set(e, pair(Previous, Position), new) | 		world:set(e, pair(Previous, Position), new) | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue