Last active
August 29, 2015 14:26
-
-
Save IceDragon200/cd0ad095c45f161f62e4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
## self_render | |
# The self render needs to be encapsulated in another object in order to handle its render parameters | |
# RenderContext is the class that currently handles wrapping these objects, since its #render method optionally takes | |
# the position and hides the internal object | |
list = [] | |
list << SpriteContext<Sprite> | |
list << Icon<Spritesheet> | |
list << Label<Text> | |
list << SpritesheetMap<Tilemap> | |
list.each { |obj| obj.render x, y, z } | |
## tree_render | |
list = [] | |
list << Tree | |
list << Sprite | |
list << Label | |
list << SpritesheetMap | |
list.each_with_object(renderer, &:render) | |
## render_tree | |
tree = Tree | |
tree << Tree | |
tree << Sprite | |
tree << Label | |
tree << SpritesheetMap | |
# The renderer needs organize certain objects by their behaviour, since you can't render a "tree" without the proper attributes, | |
# that also means everything must either be wrapped in a tree or it falls back on tree_render behaviour | |
renderer.render tree, camera |
This file contains hidden or 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
world = Moon::EntitySystem::World.new | |
## self_render | |
# Self render once again wraps all the renderable objects into YAO (Yet Another Object) which tracks all the changes | |
# in the ECS and creates/removes objects as needed, as you can guess this is fugly as it requires monolith classes who KNOW EVERYTHING. | |
# Example is too damn large to place here | |
## tree_render | |
class EcsContext | |
attr_accessor :world | |
def initialize(world) | |
@world = world | |
end | |
def render(renderer) | |
@world.filter(:render) do |r| | |
rendererer.render r.shader, r.vbo, ... etc | |
end | |
end | |
end | |
ecs_context = EcsContext.new world | |
ecs_context.render renderer | |
## render_tree | |
# possibly not going to work... | |
renderer.render world.filter(:render), camera |
This file contains hidden or 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
# In this case, we pass in a tree to the renderer | |
# This assumes that the renderer knows the structure of the tree and expects certain values from it. | |
tree = Tree | |
obj = Sprite || Spritesheet || Tilemap || Text | |
camera = Camera2d || Camera3d | |
tree.add sprite | |
renderer.render tree, camera | |
# This assumes: | |
# 1. The tree can be traversed externally | |
# 2. All objects in the tree conform to the renderer's schema |
This file contains hidden or 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
# Assumes that there is a global render state | |
# This is what we currently do | |
obj = Sprite || Spritesheet || Tilemap || Text | |
obj.render x, y, z | |
# Spritesheet requires a fourth parameter, so this example will not work for it | |
# In this case the object has its own render method and handles its own shader uniforms, attributes and so forth. |
This file contains hidden or 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
# In this example, the tree/object takes a renderer and uses it similar to the self_render example | |
obj = Tree || Sprite || Spritesheet || Tilemap || Text | |
obj.render renderer | |
# This however encourages private render behaviour, but makes no assumption about the rendering object's schematics |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment