-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cgen, checker: fix wrong receiver generic resolution with embed types (…
- Loading branch information
Showing
3 changed files
with
120 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
pub type Entity = u64 | ||
type ComponentType = u16 | ||
|
||
pub struct Context { | ||
pub mut: | ||
ecs &Ecs | ||
} | ||
|
||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
pub struct EntityManager { | ||
mut: | ||
living_entity_count u64 | ||
} | ||
|
||
fn (mut self EntityManager) create_entity() Entity { | ||
entity := self.living_entity_count | ||
self.living_entity_count++ | ||
return entity | ||
} | ||
|
||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
|
||
pub interface ISystem { | ||
ecs &Ecs | ||
mut: | ||
init() | ||
} | ||
|
||
pub struct System { | ||
pub mut: | ||
ecs &Ecs | ||
} | ||
|
||
pub fn (mut self System) init() { | ||
} | ||
|
||
pub struct SystemManager { | ||
mut: | ||
system_array map[string]ISystem = {} | ||
} | ||
|
||
fn (mut self SystemManager) add_system[T]() &T { | ||
mut t := T{} | ||
self.system_array[typeof[T]().name] = t | ||
return &t | ||
} | ||
|
||
//////////////////////////////////////////////////////////////////////////// | ||
|
||
@[heap] | ||
pub struct Ecs { | ||
mut: | ||
entity_manager EntityManager | ||
system_manager SystemManager | ||
pub mut: | ||
root_entity Entity | ||
} | ||
|
||
pub fn Ecs.new() &Ecs { | ||
mut ecs := &Ecs{} | ||
ecs.root_entity = ecs.create_entity() | ||
return ecs | ||
} | ||
|
||
pub fn (mut self Ecs) create_entity() Entity { | ||
return self.entity_manager.create_entity() | ||
} | ||
|
||
pub fn (mut self Ecs) add_system[T]() { | ||
mut system := self.system_manager.add_system[T]() | ||
system.ecs = &self | ||
system.init() | ||
} | ||
|
||
//////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
|
||
struct NetworkUdpServerComponent { | ||
} | ||
|
||
struct NetworkServerSystemUdp { | ||
System | ||
} | ||
|
||
pub struct ConfigSystem { | ||
System | ||
} | ||
|
||
struct NetworkServerSystemUdpExt { | ||
NetworkServerSystemUdp | ||
} | ||
|
||
fn test_main() { | ||
mut ecs := Ecs.new() | ||
mut root_entity := ecs.create_entity() | ||
|
||
ecs.add_system[ConfigSystem]() | ||
ecs.add_system[NetworkServerSystemUdpExt]() | ||
|
||
assert true | ||
} |