diff --git a/demos/assets/shaders/additive_particles.fp b/demos/assets/shaders/additive_particles.fp new file mode 100644 index 0000000..047f647 --- /dev/null +++ b/demos/assets/shaders/additive_particles.fp @@ -0,0 +1,55 @@ +precision mediump int; +precision mediump float; +precision lowp sampler2D; +precision lowp samplerCube; + + +#ifdef GLES + #define TEX(x,y) texture2D(x,y) + #if __VERSION__ >290 + #define M_IN in mediump + #define L_IN in lowp + #else + #define M_IN varying mediump + #define L_IN varying lowp + #endif +#else + #define TEX(x,y) texture(x,y) + #if __VERSION__ > 320 + #define M_IN in + #define L_IN in + #else + #define M_IN varying + #define L_IN varying + #endif +#endif + + +M_IN vec2 uv; +M_IN vec4 color; +/* +#ifdef GLES + #if __VERSION__ >290 + in mediump vec2 uv; + #else + varying mediump vec2 uv; + #endif +#else + #if __VERSION__ > 320 + in vec2 uv; + #else + varying vec2 uv; + #endif +#endif*/ + +//layout(binding = 0)uniform sampler2D tex; + +uniform sampler2D tex; + +//layout(location = 0) out vec4 outColor; + +void main() +{ + gl_FragColor = /*TEX(tex,uv) **/ color; + if(gl_FragColor.a < 0.01)discard; +} diff --git a/demos/assets/shaders/additive_particles.vp b/demos/assets/shaders/additive_particles.vp new file mode 100644 index 0000000..2777a24 --- /dev/null +++ b/demos/assets/shaders/additive_particles.vp @@ -0,0 +1,106 @@ +precision highp float; +precision highp int; +precision lowp sampler2D; +precision lowp samplerCube; +#ifdef GLES + #if __VERSION__ >290 + #define LOC(x) layout(location = x) + #define ATT in + #define M_OUT out mediump + #define L_OUT out lowp + #else + #define LOC(x) + #define ATT attribute + #define M_OUT varying mediump + #define L_OUT varying lowp + #endif +#else + #if __VERSION__ > 320 + #define LOC(x) layout(location = x) + #define ATT in + #define M_OUT out + #define L_OUT out + #else + #define LOC(x) + #define ATT attribute + #define M_OUT varying + #define L_OUT varying + #endif +#endif +/* +#ifdef GLES + #if __VERSION__ >290 + uniform vec4 matrix_1; + uniform vec4 matrix_2; + uniform vec4 uv_transform; + + layout(location = 0) in vec2 positions; + layout(location = 1) in vec2 tex_coords; + + out mediump vec2 uv; + #else + uniform vec4 matrix_1; + uniform vec4 matrix_2; + uniform vec4 uv_transform; + + attribute vec2 positions; + attribute vec2 tex_coords; + + varying mediump vec2 uv; + #endif +#else + #if __VERSION__ > 320 + uniform vec4 matrix_1; + uniform vec4 matrix_2; + uniform vec4 uv_transform; + + layout(location = 0) in vec2 positions; + layout(location = 1) in vec2 tex_coords; + + out vec2 uv; + #else + uniform vec4 matrix_1; + uniform vec4 matrix_2; + uniform vec4 uv_transform; + + attribute vec2 positions; + attribute vec2 tex_coords; + + varying vec2 uv; + #endif +#endif*/ + +#define VBO_BATCH 1 + +M_OUT vec2 uv; +L_OUT vec4 color; + +LOC(0) ATT vec2 positions; +LOC(1) ATT vec2 tex_coords; + +#ifdef VBO_BATCH + LOC(2) ATT float depth; + LOC(3) ATT vec4 vcolor; +#else + uniform vec4 matrix_1; + uniform vec4 matrix_2; + uniform vec4 uv_transform; + uniform vec4 vcolor; + + float depth = matrix_2.z; +#endif + +void main() { + #ifdef VBO_BATCH + vec3 position = vec3(positions*4.0,1.0); + uv = tex_coords; + #else + vec3 position = mat3(matrix_1.x,matrix_1.y,0,matrix_1.z,matrix_1.w,0,matrix_2.xy,1.0) * vec3(positions,1.0); + uv = tex_coords * uv_transform.zw + uv_transform.xy; + #endif + + color = vcolor; + + gl_Position = vec4(position.xy,depth,1.0); + +} diff --git a/demos/source/app.d b/demos/source/app.d index 6808e42..2310413 100644 --- a/demos/source/app.d +++ b/demos/source/app.d @@ -41,6 +41,15 @@ struct Mouse bool left, right, middle; } +struct DemoCallbacks +{ + void function() initialize; + void function() deinitialize; + bool function() loop; + void function(SDL_Event*) event; + const (char)* tips; +} + struct Launcher { ECSJobUpdater* job_updater; @@ -49,9 +58,9 @@ struct Launcher SDL_Window* window; SDL_GLContext gl_context; EntityManager* manager; - bool function() loop; + /*bool function() loop; void function() end; - void function(SDL_Event*) event; + void function(SDL_Event*) event;*/ //void function(vec2, Tool, int, bool) tool; float scalling; ivec2 window_size = ivec2(1024,768); @@ -74,12 +83,13 @@ struct Launcher bool override_ = true; bool tool_mode = true; ToolCircle* tool_circle; + bool show_filtered; bool swap_interval = true; float windows_alpha = 0.75; - const (char)* tips; + //const (char)* tips; bool show_stat_wnd = true; bool show_tips = true; @@ -99,12 +109,14 @@ struct Launcher float draw_time = 0; } - void switchDemo(void function() start, bool function() loop, void function() end, void function(SDL_Event*) event, const (char)* tips) + DemoCallbacks demo; + + void switchDemo(DemoCallbacks callbacks)//void function() start, bool function() loop, void function() end, void function(SDL_Event*) event, const (char)* tips) { gui_manager.clear(); //launcher.ent - if(this.end)this.end(); + if(this.demo.deinitialize)this.demo.deinitialize(); manager.begin(); manager.update("clean"); @@ -118,14 +130,29 @@ struct Launcher /*launcher.manager.getSystem(CountSystem.system_id).enable(); launcher.manager.getSystem(CleanSystem.system_id).enable();//*/ - if(start)start(); - this.loop = loop; + if(callbacks.initialize)callbacks.initialize(); + demo = callbacks; + /*this.loop = loop; this.end = end; this.event = event; - this.tips = tips; + this.tips = tips;*/ //this.tool = tool; } + bool filterEntity(ref const Entity entity) + { + EntityMeta meta = entity.getMeta(); + foreach(id;gui_manager.filter_list) + { + if(!meta.hasComponent(id))return false; + } + if(used_tool == Tool.component_manipulator) + { + if(!meta.hasComponent(gui_manager.getSelectedComponent().component_id))return false; + } + return true; + } + void processTool(vec2 position, bool mode) { static struct Iterator @@ -361,7 +388,7 @@ void mainLoop(void* arg) while (SDL_PollEvent(&event)) { ImGui_ImplSDL2_ProcessEvent(&event); - if(launcher.event)launcher.event(&event); + if(launcher.demo.event)launcher.demo.event(&event); if (event.type == SDL_QUIT || (event.type == SDL_KEYDOWN && event.key.keysym.scancode == SDL_SCANCODE_ESCAPE)) { quit(); *cast(bool*)arg = false; @@ -534,22 +561,32 @@ void mainLoop(void* arg) if(igMenuItemBool("Simpe",null,false,true)) { import demos.simple; - launcher.switchDemo(&simpleStart,&simpleLoop,&simpleEnd,&simpleEvent,Simple.tips); + launcher.switchDemo(getSimpleDemo());//&simpleStart,&simpleLoop,&simpleEnd,&simpleEvent,Simple.tips); } if(igMenuItemBool("Snake",null,false,true)) { import demos.snake; - launcher.switchDemo(&snakeStart,&snakeLoop,&snakeEnd,&snakeEvent,Snake.tips); + launcher.switchDemo(getSnakeDemo());//&snakeStart,&snakeLoop,&snakeEnd,&snakeEvent,Snake.tips); } - if(igMenuItemBool("Space invaders",null,false,true)) + if(igMenuItemBool("Space Invaders",null,false,true)) { import demos.space_invaders; - launcher.switchDemo(&spaceInvadersStart,&spaceInvadersLoop,&spaceInvadersEnd,&spaceInvadersEvent,SpaceInvaders.tips); + launcher.switchDemo(getSpaceInvadersDemo());//&spaceInvadersStart,&spaceInvadersLoop,&spaceInvadersEnd,&spaceInvadersEvent,SpaceInvaders.tips); } if(igMenuItemBool("Particles",null,false,true)) { import demos.particles; - launcher.switchDemo(&particlesStart,&particlesLoop,&particlesEnd,&particlesEvent,ParticlesDemo.tips); + launcher.switchDemo(getParticlesDemo());//&particlesStart,&particlesLoop,&particlesEnd,&particlesEvent,ParticlesDemo.tips); + } + if(igMenuItemBool("Brick Breaker",null,false,true)) + { + import demos.brick_breaker; + launcher.switchDemo(getBrickBreakerDemo());//&particlesStart,&particlesLoop,&particlesEnd,&particlesEvent,ParticlesDemo.tips); + } + if(igMenuItemBool("Sandbox",null,false,true)) + { + import demos.sandbox; + launcher.switchDemo(getSanboxDemo());//&particlesStart,&particlesLoop,&particlesEnd,&particlesEvent,ParticlesDemo.tips); } igEndMenu(); } @@ -683,7 +720,7 @@ void mainLoop(void* arg) igSetNextWindowBgAlpha(launcher.windows_alpha); if(igBegin("Tips",&launcher.show_tips,ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoSavedSettings)) { - igTextWrapped(launcher.tips); + igTextWrapped(launcher.demo.tips); } igEnd(); } @@ -726,9 +763,11 @@ void mainLoop(void* arg) if(igIsItemHovered(0))igSetTooltip("Select tool (CTRL + 1,2,3)"); igCheckbox("Show Tool", &launcher.tool_show); if(igIsItemHovered(0))igSetTooltip("Show/hide graphical tool representation"); + igSameLine(0,4); + igCheckbox("Show Filtered", &launcher.show_filtered); + if(igIsItemHovered(0))igSetTooltip("Show/hide filtered entities"); if(launcher.used_tool == Tool.component_manipulator) { - igSameLine(0,4); igCheckbox("Override", &launcher.override_); } @@ -823,7 +862,7 @@ void mainLoop(void* arg) double loop_time = launcher.getTime(); launcher.job_updater.pool.tryWaitCount = 10000; - if(launcher.loop && !launcher.loop()) + if(launcher.demo.loop && !launcher.demo.loop()) { quit(); *cast(bool*)arg = false; @@ -1053,6 +1092,8 @@ int app_main(int argc, char** argv) loadGFX(); launcher.renderer.initialize(); + import game_core.rendering : TexCoordsManager; + TexCoordsManager.initialize(); import mmutils.thread_pool : ThreadPool; launcher.threads = ThreadPool.getCPUCoresCount(); @@ -1065,8 +1106,10 @@ int app_main(int argc, char** argv) import demos.space_invaders; import demos.particles; // launcher.switchDemo(&spaceInvadersStart,&spaceInvadersLoop,&spaceInvadersEnd,&spaceInvadersEvent,SpaceInvaders.tips); - launcher.switchDemo(&particlesStart,&particlesLoop,&particlesEnd,&particlesEvent,ParticlesDemo.tips); + // launcher.switchDemo(&particlesStart,&particlesLoop,&particlesEnd,&particlesEvent,ParticlesDemo.tips); // launcher.switchDemo(&simpleStart,&simpleLoop,&simpleEnd,&simpleEvent,Simple.tips); + // launcher.switchDemo(getParticlesDemo()); + launcher.switchDemo(getSimpleDemo()); } int key_num; @@ -1094,6 +1137,7 @@ int app_main(int argc, char** argv) } } + TexCoordsManager.destroy(); EntityManager.destroy(); return 0; @@ -1198,13 +1242,22 @@ void loadGFX() + + Shader vsh3; + vsh3.create(); + vsh3.load("assets/shaders/additive_particles.vp"); + vsh3.compile(); + Shader fsh3; + fsh3.create(); + fsh3.load("assets/shaders/additive_particles.fp"); + fsh3.compile(); GfxConfig.materials[2].create(); GfxConfig.materials[2].data.blend_mode = Material.BlendMode.opaque; GfxConfig.materials[2].data.mode = Material.TransformMode.position; - //Material.ShaderModule[1] modules = [Material.ShaderModule(vsh,fsh)]; - GfxConfig.materials[2].attachModules(modules); + Material.ShaderModule[1] modules3 = [Material.ShaderModule(vsh3,fsh3)]; + GfxConfig.materials[2].attachModules(modules3); //GfxConfig.materials[0]. //GfxConfig.materials[0].load(load_data.materials[i].str); GfxConfig.materials[2].compile(); diff --git a/demos/source/demos/brick_breaker.d b/demos/source/demos/brick_breaker.d new file mode 100644 index 0000000..1af22b9 --- /dev/null +++ b/demos/source/demos/brick_breaker.d @@ -0,0 +1,193 @@ +module demos.brick_breaker; + +import app; + +import bindbc.sdl; + +import bubel.ecs.attributes; +import bubel.ecs.core; +import bubel.ecs.entity; +import bubel.ecs.manager; +import bubel.ecs.std; + +import cimgui.cimgui; + +import ecs_utils.gfx.texture; +import ecs_utils.math.vector; +import ecs_utils.utils; + +import game_core.basic; +import game_core.rendering; + +extern(C): + +/*####################################################################################################################### +------------------------------------------------ Components ------------------------------------------------------------------ +#######################################################################################################################*/ + +/*struct CLocation +{ + mixin ECS.Component; + + alias location this; + + vec2 location; +}*/ + +struct CBrick +{ + mixin ECS.Component; +} + +struct CPaddle +{ + mixin ECS.Component; +} + +struct CBall +{ + mixin ECS.Component; + + ubyte radius; +} + +struct CVelocity +{ + mixin ECS.Component; + + alias value this; + + vec2 value; +} + +/*####################################################################################################################### +------------------------------------------------ Systems ------------------------------------------------------------------ +#######################################################################################################################*/ + +struct MoveSystem +{ + mixin ECS.System!64; + + struct EntitiesData + { + uint length; + CLocation[] location; + @readonly CVelocity[] velocity; + } + + void onUpdate(EntitiesData data) + { + foreach(i; 0..data.length) + { + data.location[i] += data.velocity[i] * launcher.delta_time; + } + } +} + +struct BallCollisionSystem +{ + mixin ECS.System!64; + + struct EntitiesData + { + uint length; + CLocation[] location; + CVelocity[] velocity; + } + + void onUpdate(EntitiesData data) + { + foreach(i; 0..data.length) + { + + } + } +} + +/*####################################################################################################################### +------------------------------------------------ Functions ------------------------------------------------------------------ +#######################################################################################################################*/ + +struct BrickBreakerDemo +{ + __gshared const (char)* tips = "Brick breaker demo. It's a game about destroying evil bricks."; + + EntityTemplate* tmpl; + Texture texture; +} + +__gshared BrickBreakerDemo* demo; + +void brickBreakerStart() +{ + demo = Mallocator.make!BrickBreakerDemo; + + launcher.manager.beginRegister(); + + registerRenderingModule(launcher.manager); + + launcher.manager.registerComponent!CLocation; + launcher.manager.registerComponent!CRotation; + launcher.manager.registerComponent!CScale; + launcher.manager.registerComponent!CTexCoords; + launcher.manager.registerComponent!CTexCoordsIndex; + launcher.manager.registerComponent!CVelocity; + + launcher.manager.registerSystem!MoveSystem(-100); + launcher.manager.registerSystem!BallCollisionSystem(-99); + + launcher.manager.endRegister(); + + demo.texture.create(); + demo.texture.load("assets/textures/atlas.png"); + + launcher.manager.beginRegister(); + + launcher.manager.registerComponent!CLocation; + + launcher.manager.endRegister(); +} + +void brickBreakerEnd() +{ + launcher.manager.getSystem(MoveSystem.system_id).disable(); + launcher.manager.getSystem(DrawSystem.system_id).disable(); + + demo.texture.destroy(); + + Mallocator.dispose(demo); +} + +void brickBreakerEvent(SDL_Event* event) +{ +} + +bool brickBreakerLoop() +{ + launcher.render_position = (vec2(launcher.window_size.x,launcher.window_size.y)*launcher.scalling - vec2(400,300)) * 0.5; + + launcher.manager.begin(); + if(launcher.multithreading) + { + launcher.job_updater.begin(); + launcher.manager.updateMT(); + launcher.job_updater.call(); + } + else + { + launcher.manager.update(); + } + launcher.manager.end(); + + return true; +} + +DemoCallbacks getBrickBreakerDemo() +{ + DemoCallbacks demo; + demo.initialize = &brickBreakerStart; + demo.deinitialize = &brickBreakerEnd; + demo.loop = &brickBreakerLoop; + demo.tips = .demo.tips; + return demo; +} \ No newline at end of file diff --git a/demos/source/demos/particles.d b/demos/source/demos/particles.d index 2242ecf..8dac7ff 100644 --- a/demos/source/demos/particles.d +++ b/demos/source/demos/particles.d @@ -17,6 +17,7 @@ import ecs_utils.math.vector; import ecs_utils.utils; import game_core.basic; +import game_core.rendering; import gui.attributes; @@ -115,7 +116,7 @@ struct CParticleLife /*####################################################################################################################### ------------------------------------------------ Systems ------------------------------------------------------------------ #######################################################################################################################*/ - +/* struct DrawSystem { mixin ECS.System!32; @@ -162,7 +163,7 @@ struct DrawSystem } } -} +}*/ struct MoveSystem { @@ -338,10 +339,10 @@ struct PlayAreaSystem { foreach(i; 0..data.length) { - if(data.locations[i].x > 400)launcher.manager.removeEntity(data.entity[i].id); - else if(data.locations[i].x < 0)launcher.manager.removeEntity(data.entity[i].id); - if(data.locations[i].y > 300)launcher.manager.removeEntity(data.entity[i].id); - else if(data.locations[i].y < 0)launcher.manager.removeEntity(data.entity[i].id); + if(data.locations[i].x > 440)launcher.manager.removeEntity(data.entity[i].id); + else if(data.locations[i].x < -40)launcher.manager.removeEntity(data.entity[i].id); + if(data.locations[i].y > 340)launcher.manager.removeEntity(data.entity[i].id); + else if(data.locations[i].y < -40)launcher.manager.removeEntity(data.entity[i].id); } } } @@ -452,16 +453,24 @@ void particlesStart() launcher.manager.beginRegister(); + registerRenderingModule(launcher.manager); + launcher.manager.registerComponent!CLocation; //launcher.manager.registerComponent!CTexCoords; launcher.manager.registerComponent!CColor; launcher.manager.registerComponent!CVelocity; + launcher.manager.registerComponent!CScale; + launcher.manager.registerComponent!CTexCoords; + launcher.manager.registerComponent!CTexCoordsIndex; + launcher.manager.registerComponent!CRotation; + launcher.manager.registerComponent!CDepth; launcher.manager.registerComponent!CAttractor; launcher.manager.registerComponent!CDamping; launcher.manager.registerComponent!CGravity; launcher.manager.registerComponent!CVortex; launcher.manager.registerComponent!CParticleLife; launcher.manager.registerComponent!CForceRange; + launcher.manager.registerComponent!CMaterialIndex; launcher.manager.registerSystem!MoveSystem(0); launcher.manager.registerSystem!DrawSystem(100); @@ -476,6 +485,12 @@ void particlesStart() launcher.manager.endRegister(); + DrawSystem* draw_system = launcher.manager.getSystem!DrawSystem; + draw_system.default_data.size = vec2(2,2); + draw_system.default_data.coords = vec4(246,64,2,2)*px; + draw_system.default_data.material_id = 2; + draw_system.default_data.texture = particles_demo.texture; + launcher.gui_manager.addSystem(MoveSystem.system_id,"Move System"); launcher.gui_manager.addSystem(DrawSystem.system_id,"Draw System"); launcher.gui_manager.addSystem(PlayAreaSystem.system_id,"Play Area System"); @@ -498,8 +513,11 @@ void particlesStart() launcher.gui_manager.addComponent(CGravity(),"Gravity"); EntityTemplate* tmpl; - EntityTemplate* base_tmpl = launcher.manager.allocateTemplate([CLocation.component_id, CColor.component_id, CVelocity.component_id, CDamping.component_id].staticArray); + EntityTemplate* base_tmpl = launcher.manager.allocateTemplate([CTexCoords.component_id, CLocation.component_id, CColor.component_id, CVelocity.component_id, CDamping.component_id, CScale.component_id, CMaterialIndex.component_id].staticArray); base_tmpl.getComponent!CColor().value = 0xFF251010; + base_tmpl.getComponent!CScale().value = vec2(2); + base_tmpl.getComponent!CTexCoords().value = vec4(246,64,2,2)*px; + base_tmpl.getComponent!CMaterialIndex().value = 2; launcher.gui_manager.addTemplate(base_tmpl,"Particle"); // tmpl = launcher.manager.allocateTemplate(base_tmpl); // tmpl.getComponent!CColor().value = 0xFF251010; @@ -515,7 +533,8 @@ void particlesStart() // tmpl = launcher.manager.allocateTemplate(tmpl); // tmpl.getComponent!CDamping().power = 4; // launcher.gui_manager.addTemplate(tmpl,"Particle (damping!)"); - tmpl = launcher.manager.allocateTemplate([CAttractor.component_id, CLocation.component_id, CForceRange.component_id].staticArray); + tmpl = launcher.manager.allocateTemplate([CAttractor.component_id, CLocation.component_id, CForceRange.component_id, CScale.component_id].staticArray); + tmpl.getComponent!CScale().value = vec2(4); launcher.gui_manager.addTemplate(tmpl,"Attractor"); tmpl = launcher.manager.allocateTemplate(tmpl, [CVortex.component_id].staticArray); launcher.gui_manager.addTemplate(tmpl,"Vortex"); @@ -555,4 +574,14 @@ bool particlesLoop() launcher.manager.end(); return true; +} + +DemoCallbacks getParticlesDemo() +{ + DemoCallbacks demo; + demo.initialize = &particlesStart; + demo.deinitialize = &particlesEnd; + demo.loop = &particlesLoop; + demo.tips = ParticlesDemo.tips; + return demo; } \ No newline at end of file diff --git a/demos/source/demos/sandbox.d b/demos/source/demos/sandbox.d new file mode 100644 index 0000000..69a2ef2 --- /dev/null +++ b/demos/source/demos/sandbox.d @@ -0,0 +1,89 @@ +module demos.sandbox; + +import bindbc.sdl; + +import demos.simple; +import demos.snake; +import demos.space_invaders; +import demos.particles; + +import game_core.rendering; + +import app; + +import ecs_utils.math.vector; + +extern(C): + +void sandboxStart() +{ + simpleStart(); + snakeStart(); + spaceInvadersStart(); + particlesStart(); + + DrawSystem* draw_system = launcher.manager.getSystem!DrawSystem; + draw_system.default_data.size = vec2(16,16); + draw_system.default_data.coords = vec4(0,48,16,16)*demos.simple.px; + draw_system.default_data.material_id = 0; + draw_system.default_data.texture = particles_demo.texture; + draw_system.default_data.color = 0x80808080; +} + +void sandboxEnd() +{ + simpleEnd(); + snakeEnd(); + spaceInvadersEnd(); + particlesEnd(); +} +/* +void sandboxEvent(SDL_Event* event) +{ +}*/ + +bool sandboxLoop() +{ + launcher.render_position = (vec2(launcher.window_size.x,launcher.window_size.y)*launcher.scalling - vec2(400,300)) * 0.5; + + launcher.manager.begin(); + + float delta_time = launcher.delta_time; + if(delta_time > 2000)delta_time = 2000; + __gshared float time = 0; + + /*if(launcher.getKeyState(SDL_SCANCODE_SPACE))time += delta_time * 3; + else */ + time += delta_time; + + while(time > 100) + { + time -= 100; + + launcher.manager.update("fixed"); + } + + if(launcher.multithreading) + { + launcher.job_updater.begin(); + launcher.manager.updateMT(); + launcher.job_updater.call(); + } + else + { + launcher.manager.update(); + } + launcher.manager.end(); + + return true; +} + +DemoCallbacks getSanboxDemo() +{ + DemoCallbacks demo; + demo.initialize = &sandboxStart; + demo.deinitialize = &sandboxEnd; + demo.loop = &sandboxLoop; + demo.tips = "tips"; + return demo; +} \ No newline at end of file diff --git a/demos/source/demos/simple.d b/demos/source/demos/simple.d index 6876e4f..1aafcb2 100644 --- a/demos/source/demos/simple.d +++ b/demos/source/demos/simple.d @@ -17,9 +17,12 @@ import ecs_utils.math.vector; import ecs_utils.utils; import game_core.basic; +import game_core.rendering; extern(C): +enum float px = 1.0/512.0; + /*####################################################################################################################### ------------------------------------------------ Components ------------------------------------------------------------------ #######################################################################################################################*/ @@ -36,7 +39,7 @@ extern(C): /*####################################################################################################################### ------------------------------------------------ Systems ------------------------------------------------------------------ #######################################################################################################################*/ - +/* struct DrawSystem { mixin ECS.System!32; @@ -66,13 +69,9 @@ struct DrawSystem draw_data.position = data.locations[i]; draw_data.depth = cast(ushort)(data.locations[i].y); launcher.renderer.draw(draw_data); - //launcher.renderer.draw(simple.texture, data.locations[i], vec2(16,16), vec4(0,0,1,1), cast(ushort)(data.locations[i].y), 0x80808080, 0, 0, 0, data.job_id); - // launcher.renderer.draw(data.textures[i].tex, data.locations[i].location, vec2(16,16), vec4(0,0,1,1), 0, 0x80808080, 0, 0, 0, data.job_id); - //draw(renderer, data.textures[i].tex, data.locations[i], vec2(32,32), vec4(0,0,1,1)); } - //if(data.thread_id == 0)launcher.renderer.pushData(); } -} +}*/ struct MoveSystem { @@ -113,22 +112,30 @@ void simpleStart() simple = Mallocator.make!Simple; simple.texture.create(); - simple.texture.load("assets/textures/buckler.png"); + simple.texture.load("assets/textures/atlas.png"); launcher.manager.beginRegister(); + registerRenderingModule(launcher.manager); + launcher.manager.registerComponent!CLocation; launcher.manager.registerSystem!MoveSystem(0); - launcher.manager.registerSystem!DrawSystem(1); + // launcher.manager.registerSystem!DrawSystem(1); launcher.manager.endRegister(); + + DrawSystem* draw_system = launcher.manager.getSystem!DrawSystem; + draw_system.default_data.color = 0x80808080; + draw_system.default_data.texture = simple.texture; + draw_system.default_data.size = vec2(16,16); + draw_system.default_data.coords = vec4(0,48,16,16)*px;//vec4(0,0,1,1); - launcher.gui_manager.addSystem(MoveSystem.system_id,"Move System"); + launcher.gui_manager.addSystem(MoveSystem.system_id,"Move Up System"); launcher.gui_manager.addSystem(DrawSystem.system_id,"Draw System"); - ushort[1] components = [CLocation.component_id]; - simple.tmpl = launcher.manager.allocateTemplate(components); + simple.tmpl = launcher.manager.allocateTemplate([CLocation.component_id, CDrawDefault.component_id].staticArray); + //*simple.tmpl.getComponent!CTexCoordsIndex = TexCoordsManager.instance.getCoordIndex(vec4(0,48,16,16)*px); //CLocation* loc_comp = simple.tmpl.getComponent!CLocation; launcher.gui_manager.addTemplate(simple.tmpl, "Basic"); @@ -186,4 +193,14 @@ bool simpleLoop() launcher.manager.end(); return true; +} + +DemoCallbacks getSimpleDemo() +{ + DemoCallbacks demo; + demo.initialize = &simpleStart; + demo.deinitialize = &simpleEnd; + demo.loop = &simpleLoop; + demo.tips = simple.tips; + return demo; } \ No newline at end of file diff --git a/demos/source/demos/snake.d b/demos/source/demos/snake.d index c42f690..8ff0be6 100644 --- a/demos/source/demos/snake.d +++ b/demos/source/demos/snake.d @@ -851,6 +851,8 @@ __gshared Snake* snake; void snakeStart() { + import game_core.rendering; + snake = Mallocator.make!Snake; snake.texture.create(); @@ -860,6 +862,8 @@ void snakeStart() launcher.manager.registerPass("fixed"); + registerRenderingModule(launcher.manager); + launcher.manager.registerComponent!CLocation; launcher.manager.registerComponent!CILocation; launcher.manager.registerComponent!CSnake; @@ -983,4 +987,14 @@ bool snakeLoop() launcher.manager.end(); return true; +} + +DemoCallbacks getSnakeDemo() +{ + DemoCallbacks demo; + demo.initialize = &snakeStart; + demo.deinitialize = &snakeEnd; + demo.loop = &snakeLoop; + demo.tips = snake.tips; + return demo; } \ No newline at end of file diff --git a/demos/source/demos/space_invaders.d b/demos/source/demos/space_invaders.d index 311feb3..b249fc1 100644 --- a/demos/source/demos/space_invaders.d +++ b/demos/source/demos/space_invaders.d @@ -401,8 +401,8 @@ struct CParticleEmitter { mixin ECS.Component; - vec2 range; - vec2 time_range; + vec2 range = vec2(0,0); + vec2 time_range = vec2(500,1000); ///due to multithreading there should be separate template for every thread. ///It can be array of tempaltes or (like in this demo) simply index of template; uint tmpl_id; @@ -829,7 +829,7 @@ struct ShipWeaponSystem void create() { tower1_tmpl = launcher.manager.allocateTemplate( - [CHitMark.component_id, CHitPoints.component_id, CLocation.component_id, + [CColor.component_id, CHitMark.component_id, CHitPoints.component_id, CLocation.component_id, CTexCoords.component_id, CScale.component_id, CEnemy.component_id, CShootGrid.component_id, CGuild.component_id, CInit.component_id, CChildren.component_id, CDepth.component_id, CTargetParent.component_id, @@ -959,7 +959,7 @@ struct MoveToParentTargetSystem } } } - +/* struct DrawSystem { mixin ECS.System!32; @@ -1088,7 +1088,7 @@ struct DrawSystem } //if(data.thread_id == 0)launcher.renderer.pushData(); } -} +}*/ struct CollisionSystem { @@ -1325,7 +1325,7 @@ struct BulletsCollisionSystem uint length; const (Entity)[] entity; @readonly CLocation[] location; - @readonly CBullet[] laser; + @readonly CBullet[] bullet; @readonly CGuild[] guild; } @@ -1336,7 +1336,7 @@ struct BulletsCollisionSystem { if(space_invaders.shoot_grid.test(id, data.location[i], cast(ubyte)(~(1 << data.guild[i].guild)))) { - launcher.manager.sendEvent(id, EBulletHit(data.entity[i].id,1)); + launcher.manager.sendEvent(id, EBulletHit(data.entity[i].id,data.bullet[i].damage)); //launcher.manager.removeEntity(data.entity[i].id); } } @@ -1631,6 +1631,7 @@ struct HitMarkingSystem { uint length; CHitMark[] mark; + CColor[] color; } void onUpdate(EntitiesData data) @@ -1640,6 +1641,7 @@ struct HitMarkingSystem //if(data.mark[i] < 10)data.mark[i] = 0; //else data.mark[i] -= 1; data.mark[i] = cast(ubyte)(data.mark[i] * 0.9); + data.color[i] = 0x80808080 + 0x01010101 * data.mark[i]; } } } @@ -2339,6 +2341,8 @@ void spaceInvadersStart() launcher.manager.registerDependency(ShootGridDependency); + registerRenderingModule(launcher.manager); + launcher.manager.registerComponent!CLocation; launcher.manager.registerComponent!CTexCoords; //launcher.manager.registerComponent!CTexture; @@ -2416,6 +2420,10 @@ void spaceInvadersStart() launcher.manager.endRegister(); + DrawSystem* draw_system = launcher.manager.getSystem!DrawSystem; + draw_system.default_data.color = 0x80808080; + draw_system.default_data.texture = space_invaders.texture; + launcher.gui_manager.addComponent(CInput(),"Input"); launcher.gui_manager.addComponent(CShip(),"Ship"); launcher.gui_manager.addComponent(CEnemy(),"Enemy"); @@ -2482,7 +2490,7 @@ void spaceInvadersStart() //launcher.manager.getSystem(CleanSystem.system_id).disable(); { space_invaders.ship_tmpl = launcher.manager.allocateTemplate( - [CVelocity.component_id, CHitMark.component_id, CHitPoints.component_id, + [CVelocity.component_id, CColor.component_id, CHitMark.component_id, CHitPoints.component_id, CLocation.component_id, CTexCoords.component_id, CInput.component_id, CShip.component_id, CScale.component_id, CColliderScale.component_id, CShootDirection.component_id, CShootGrid.component_id, CGuild.component_id, @@ -2517,7 +2525,7 @@ void spaceInvadersStart() { boss_tmpl = launcher.manager.allocateTemplate( - [CHitMark.component_id, CParts.component_id, CLocation.component_id, + [CColor.component_id, CHitMark.component_id, CParts.component_id, CLocation.component_id, CTexCoords.component_id, CScale.component_id, CEnemy.component_id, CBoss.component_id, CGuild.component_id, CInit.component_id, CChildren.component_id, CSideMove.component_id, CVelocity.component_id, @@ -2540,7 +2548,7 @@ void spaceInvadersStart() { tower_tmpl = launcher.manager.allocateTemplate( - [CHitMark.component_id, CHitPoints.component_id, CLocation.component_id, + [CColor.component_id, CHitMark.component_id, CHitPoints.component_id, CLocation.component_id, CTexCoords.component_id, CScale.component_id, CEnemy.component_id, CShootGrid.component_id, CGuild.component_id, CInit.component_id, CChildren.component_id].staticArray @@ -2554,7 +2562,7 @@ void spaceInvadersStart() { space_invaders.enemy_tmpl = launcher.manager.allocateTemplate( - [CWeaponLocation.component_id, CHitMark.component_id, CHitPoints.component_id, + [CWeaponLocation.component_id, CColor.component_id, CHitMark.component_id, CHitPoints.component_id, CVelocity.component_id, CAutoShoot.component_id, CLocation.component_id, CTexCoords.component_id, CScale.component_id, CWeapon.component_id, CEnemy.component_id, CShootDirection.component_id, CShootGrid.component_id, @@ -2733,4 +2741,14 @@ bool spaceInvadersLoop() }*/ return true; +} + +DemoCallbacks getSpaceInvadersDemo() +{ + DemoCallbacks demo; + demo.initialize = &spaceInvadersStart; + demo.deinitialize = &spaceInvadersEnd; + demo.loop = &spaceInvadersLoop; + demo.tips = space_invaders.tips; + return demo; } \ No newline at end of file diff --git a/demos/source/game_core/rendering.d b/demos/source/game_core/rendering.d index de5f0b5..bee9367 100644 --- a/demos/source/game_core/rendering.d +++ b/demos/source/game_core/rendering.d @@ -1,13 +1,30 @@ module game_core.rendering; -import bubel.ecs.core; import bubel.ecs.attributes; +import bubel.ecs.core; +import bubel.ecs.std; -import ecs_utils.math.vector; import ecs_utils.gfx.texture; +import ecs_utils.math.vector; import game_core.basic; +void registerRenderingModule(EntityManager* manager) +{ + manager.registerComponent!CLocation; + manager.registerComponent!CScale; + manager.registerComponent!CRotation; + manager.registerComponent!CDepth; + manager.registerComponent!CColor; + manager.registerComponent!CSelected; + manager.registerComponent!CTexCoords; + manager.registerComponent!CTexCoordsIndex; + manager.registerComponent!CMaterialIndex; + manager.registerComponent!CDrawDefault; + + manager.registerSystem!DrawSystem(100); +} + struct CTexCoords { mixin ECS.Component; @@ -19,16 +36,63 @@ struct CTexCoords struct CTexCoordsIndex { - mixin ECS.Component; + mixin ECS.Component; + + alias value this; ushort value; } +struct CMaterialIndex +{ + mixin ECS.Component; + + alias value this; + + ushort value; +} + +struct CDrawDefault +{ + mixin ECS.Component; +} + struct TexCoordsManager { import bubel.ecs.vector; import bubel.ecs.hash_map; + __gshared TexCoordsManager* instance = null; + + static void initialize() + { + if(instance is null)instance = Mallocator.make!TexCoordsManager; + } + + static void destroy() + { + if(instance)Mallocator.dispose(instance); + instance = null; + } + + vec4 get(ushort index) + { + if(index > coords.length)return vec4(0,0,1,1); + else return coords[index]; + } + + ushort getCoordIndex(vec4 coords) + { + ushort ret = coords_map.get(coords, ushort.max); + if(ret != ushort.max) + { + return ret; + } + this.coords.add(coords); + coords_map.add(coords, cast(ushort)(this.coords.length - 1)); + return cast(ushort)(this.coords.length - 1); + } + Vector!vec4 coords; HashMap!(vec4,ushort) coords_map; } @@ -44,17 +108,34 @@ struct DrawSystem uint length; //uint thread_id; uint job_id; + const(Entity)[] entity; @readonly CLocation[] locations; - @readonly CScale[] scale; - @readonly CTexCoords[] texcoord; - // @readonly @optional CTexCoords[] texcoord; - // @readonly @optional CTexCoordsIndex[] texcoord_index; + @readonly @optional CScale[] scale; + // @readonly CTexCoords[] texcoord; + @readonly @optional CTexCoords[] texcoord; + @readonly @optional CTexCoordsIndex[] texcoord_index; @readonly @optional CRotation[] rotation; @readonly @optional CDepth[] depth; @readonly @optional CColor[] color; + @readonly @optional CMaterialIndex[] material; + @readonly @optional CDrawDefault[] draw_default; } Renderer.DrawData default_data; + float color_time = 0; + uint select_color = 0; + + bool onBegin() + { + import app : launcher; + color_time += launcher.delta_time * 0.001; + color_time = color_time - cast(int)(color_time*0.5)*2; + float ratio = color_time - cast(int)color_time; + if(color_time > 1)ratio = 1 - ratio; + uint multipler = cast(uint)(0x60 * ratio); + select_color = 0xA0A0A0A0 + cast(uint)(0x01010101 * multipler); + return true; + } void onUpdate(EntitiesData data) { @@ -63,10 +144,368 @@ struct DrawSystem if(launcher.renderer.prepared_items >= launcher.renderer.MaxObjects)return;//simple leave loop if max visible objects count was reached Renderer.DrawData draw_data = default_data; draw_data.thread_id = data.job_id; - - if(!data.depth) + + if(launcher.show_filtered && launcher.filterEntity(data.entity[0])) { - if(!data.color) + draw_data.color = select_color; + data.color = null; + } + //import std.stdio; + //writeln(data.draw_default); + //if(data.draw_default is null && data.texcoord is null && data.texcoord_index is null && !data.entity[0].hasComponent(CDrawDefault.component_id))return; + + if(data.texcoord is null && data.texcoord_index is null && data.draw_default is null)return; + + + foreach(i; 0..data.length) + { + draw_data.position = data.locations[i]; + if(data.color)draw_data.color = data.color[i]; + if(data.depth)draw_data.depth = data.depth[i]; + if(data.rotation)draw_data.angle = data.rotation[i]; + if(data.scale)draw_data.size = data.scale[i]; + if(data.texcoord)draw_data.coords = data.texcoord[i]; + else if(data.texcoord_index)draw_data.coords = TexCoordsManager.instance.get(data.texcoord_index[i]); + if(data.material)draw_data.material_id = data.material[i]; + launcher.renderer.draw(draw_data); + }//*/ + + /* + ubyte mode; + if(data.scale)mode |= 0x01; + if(data.texcoord)mode |= 0x02; + if(data.texcoord_index)mode |= 0x04; + if(data.rotation)mode |= 0x08; + if(data.depth)mode |= 0x10; + if(data.color)mode |= 0x20; + + if(launcher.show_filtered && launcher.filterEntity(data.entity[0])) + { + draw_data.color = select_color; + mode &= ~0x20; + //goto draw_nocolor; + } + + switch(mode) + { + case 0: + foreach(i; 0..data.length) + { + draw_data.position = data.locations[i]; + launcher.renderer.draw(draw_data); + } + break; + + case 0b000001: + foreach(i; 0..data.length) + { + draw_data.position = data.locations[i]; + draw_data.size = data.scale[i]; + launcher.renderer.draw(draw_data); + } + break; + + case 0b000010: + foreach(i; 0..data.length) + { + draw_data.position = data.locations[i]; + draw_data.coords = data.texcoord[i]; + launcher.renderer.draw(draw_data); + } + break; + case 0b000011: + foreach(i; 0..data.length) + { + draw_data.position = data.locations[i]; + draw_data.size = data.scale[i]; + draw_data.coords = data.texcoord[i]; + launcher.renderer.draw(draw_data); + } + break; + + case 0b001000: + foreach(i; 0..data.length) + { + draw_data.position = data.locations[i]; + draw_data.angle = data.rotation[i]; + launcher.renderer.draw(draw_data); + } + break; + case 0b001001: + foreach(i; 0..data.length) + { + draw_data.position = data.locations[i]; + draw_data.angle = data.rotation[i]; + draw_data.size = data.scale[i]; + launcher.renderer.draw(draw_data); + } + break; + case 0b001010: + foreach(i; 0..data.length) + { + draw_data.position = data.locations[i]; + draw_data.angle = data.rotation[i]; + draw_data.coords = data.texcoord[i]; + launcher.renderer.draw(draw_data); + } + break; + case 0b001011: + foreach(i; 0..data.length) + { + draw_data.position = data.locations[i]; + draw_data.angle = data.rotation[i]; + draw_data.size = data.scale[i]; + draw_data.coords = data.texcoord[i]; + launcher.renderer.draw(draw_data); + } + break; + + + case 0b010000: + foreach(i; 0..data.length) + { + draw_data.position = data.locations[i]; + draw_data.depth = data.depth[i]; + launcher.renderer.draw(draw_data); + } + break; + case 0b010001: + foreach(i; 0..data.length) + { + draw_data.position = data.locations[i]; + draw_data.depth = data.depth[i]; + draw_data.size = data.scale[i]; + launcher.renderer.draw(draw_data); + } + break; + case 0b010010: + foreach(i; 0..data.length) + { + draw_data.position = data.locations[i]; + draw_data.depth = data.depth[i]; + draw_data.coords = data.texcoord[i]; + launcher.renderer.draw(draw_data); + } + break; + case 0b010011: + foreach(i; 0..data.length) + { + draw_data.position = data.locations[i]; + draw_data.depth = data.depth[i]; + draw_data.size = data.scale[i]; + draw_data.coords = data.texcoord[i]; + launcher.renderer.draw(draw_data); + } + break; + case 0b011000: + foreach(i; 0..data.length) + { + draw_data.position = data.locations[i]; + draw_data.depth = data.depth[i]; + draw_data.angle = data.rotation[i]; + launcher.renderer.draw(draw_data); + } + break; + case 0b011001: + foreach(i; 0..data.length) + { + draw_data.position = data.locations[i]; + draw_data.depth = data.depth[i]; + draw_data.angle = data.rotation[i]; + draw_data.size = data.scale[i]; + launcher.renderer.draw(draw_data); + } + break; + case 0b011010: + foreach(i; 0..data.length) + { + draw_data.position = data.locations[i]; + draw_data.depth = data.depth[i]; + draw_data.angle = data.rotation[i]; + draw_data.coords = data.texcoord[i]; + launcher.renderer.draw(draw_data); + } + break; + case 0b011011: + foreach(i; 0..data.length) + { + draw_data.position = data.locations[i]; + draw_data.depth = data.depth[i]; + draw_data.angle = data.rotation[i]; + draw_data.size = data.scale[i]; + draw_data.coords = data.texcoord[i]; + launcher.renderer.draw(draw_data); + } + break; + + + case 0b100000: + foreach(i; 0..data.length) + { + draw_data.position = data.locations[i]; + draw_data.color = data.color[i]; + launcher.renderer.draw(draw_data); + } + break; + case 0b100001: + foreach(i; 0..data.length) + { + draw_data.position = data.locations[i]; + draw_data.color = data.color[i]; + draw_data.size = data.scale[i]; + launcher.renderer.draw(draw_data); + } + break; + case 0b100010: + foreach(i; 0..data.length) + { + draw_data.position = data.locations[i]; + draw_data.color = data.color[i]; + draw_data.coords = data.texcoord[i]; + launcher.renderer.draw(draw_data); + } + break; + case 0b100011: + foreach(i; 0..data.length) + { + draw_data.position = data.locations[i]; + draw_data.color = data.color[i]; + draw_data.size = data.scale[i]; + draw_data.coords = data.texcoord[i]; + launcher.renderer.draw(draw_data); + } + break; + case 0b101000: + foreach(i; 0..data.length) + { + draw_data.position = data.locations[i]; + draw_data.color = data.color[i]; + draw_data.angle = data.rotation[i]; + launcher.renderer.draw(draw_data); + } + break; + case 0b101001: + foreach(i; 0..data.length) + { + draw_data.position = data.locations[i]; + draw_data.color = data.color[i]; + draw_data.angle = data.rotation[i]; + draw_data.size = data.scale[i]; + launcher.renderer.draw(draw_data); + } + break; + case 0b101010: + foreach(i; 0..data.length) + { + draw_data.position = data.locations[i]; + draw_data.color = data.color[i]; + draw_data.angle = data.rotation[i]; + draw_data.coords = data.texcoord[i]; + launcher.renderer.draw(draw_data); + } + break; + case 0b101011: + foreach(i; 0..data.length) + { + draw_data.position = data.locations[i]; + draw_data.color = data.color[i]; + draw_data.angle = data.rotation[i]; + draw_data.size = data.scale[i]; + draw_data.coords = data.texcoord[i]; + launcher.renderer.draw(draw_data); + } + break; + case 0b110000: + foreach(i; 0..data.length) + { + draw_data.position = data.locations[i]; + draw_data.color = data.color[i]; + draw_data.depth = data.depth[i]; + launcher.renderer.draw(draw_data); + } + break; + case 0b110001: + foreach(i; 0..data.length) + { + draw_data.position = data.locations[i]; + draw_data.color = data.color[i]; + draw_data.depth = data.depth[i]; + draw_data.size = data.scale[i]; + launcher.renderer.draw(draw_data); + } + break; + case 0b110010: + foreach(i; 0..data.length) + { + draw_data.position = data.locations[i]; + draw_data.color = data.color[i]; + draw_data.depth = data.depth[i]; + draw_data.coords = data.texcoord[i]; + launcher.renderer.draw(draw_data); + } + break; + case 0b110011: + foreach(i; 0..data.length) + { + draw_data.position = data.locations[i]; + draw_data.color = data.color[i]; + draw_data.depth = data.depth[i]; + draw_data.size = data.scale[i]; + draw_data.coords = data.texcoord[i]; + launcher.renderer.draw(draw_data); + } + break; + case 0b111000: + foreach(i; 0..data.length) + { + draw_data.position = data.locations[i]; + draw_data.color = data.color[i]; + draw_data.depth = data.depth[i]; + draw_data.angle = data.rotation[i]; + launcher.renderer.draw(draw_data); + } + break; + case 0b111001: + foreach(i; 0..data.length) + { + draw_data.position = data.locations[i]; + draw_data.color = data.color[i]; + draw_data.depth = data.depth[i]; + draw_data.angle = data.rotation[i]; + draw_data.size = data.scale[i]; + launcher.renderer.draw(draw_data); + } + break; + case 0b111010: + foreach(i; 0..data.length) + { + draw_data.position = data.locations[i]; + draw_data.color = data.color[i]; + draw_data.depth = data.depth[i]; + draw_data.angle = data.rotation[i]; + draw_data.coords = data.texcoord[i]; + launcher.renderer.draw(draw_data); + } + break; + case 0b111011: + foreach(i; 0..data.length) + { + draw_data.position = data.locations[i]; + draw_data.color = data.color[i]; + draw_data.depth = data.depth[i]; + draw_data.angle = data.rotation[i]; + draw_data.size = data.scale[i]; + draw_data.coords = data.texcoord[i]; + launcher.renderer.draw(draw_data); + } + break; + default:break; + }//*/ +/* + if(!data.color) + { + draw_nocolor: + if(!data.depth) { if(!data.rotation) { @@ -96,7 +535,7 @@ struct DrawSystem { foreach(i; 0..data.length) { - draw_data.color = data.color[i]; + draw_data.depth = data.depth[i]; draw_data.coords = data.texcoord[i]; draw_data.size = data.scale[i]; draw_data.position = data.locations[i]; @@ -107,7 +546,7 @@ struct DrawSystem { foreach(i; 0..data.length) { - draw_data.color = data.color[i]; + draw_data.depth = data.depth[i]; draw_data.angle = data.rotation[i]; draw_data.coords = data.texcoord[i]; draw_data.size = data.scale[i]; @@ -119,13 +558,13 @@ struct DrawSystem } else { - if(!data.color) + if(!data.depth) { if(!data.rotation) { foreach(i; 0..data.length) { - draw_data.depth = data.depth[i]; + draw_data.color = data.color[i]; draw_data.coords = data.texcoord[i]; draw_data.size = data.scale[i]; draw_data.position = data.locations[i]; @@ -136,7 +575,7 @@ struct DrawSystem { foreach(i; 0..data.length) { - draw_data.depth = data.depth[i]; + draw_data.color = data.color[i]; draw_data.angle = data.rotation[i]; draw_data.coords = data.texcoord[i]; draw_data.size = data.scale[i]; @@ -165,7 +604,6 @@ struct DrawSystem { draw_data.depth = data.depth[i]; draw_data.color = data.color[i]; - draw_data.angle = data.rotation[i]; draw_data.coords = data.texcoord[i]; draw_data.size = data.scale[i]; draw_data.position = data.locations[i]; @@ -173,6 +611,6 @@ struct DrawSystem } } } - } + }*/ } } \ No newline at end of file diff --git a/demos/source/gui/component.d b/demos/source/gui/component.d index b19f069..e65dee4 100644 --- a/demos/source/gui/component.d +++ b/demos/source/gui/component.d @@ -47,7 +47,9 @@ struct VariableGUI enum_, color, vec2, - ivec2 + ivec2, + vec4, + ivec4 } Type type; const (char)* name; diff --git a/demos/source/gui/manager.d b/demos/source/gui/manager.d index 3f6e6cb..3745d9d 100644 --- a/demos/source/gui/manager.d +++ b/demos/source/gui/manager.d @@ -93,9 +93,13 @@ struct GUIManager void addSystem(ushort id, const (char)* name, bool enabled = true) { + foreach(ref sys; systems) + { + if(sys.id == id)return; + } System* system = launcher.manager.getSystem(id); //const (char)* name = - systems.add(SystemGUI(name,system,enabled)); + systems.add(SystemGUI(name,id,enabled)); } void addTemplate(ushort[] components, const (char)* name) @@ -143,7 +147,23 @@ struct GUIManager //pragma(msg,member_type); //pragma(msg,__traits(getMember, T, member).offsetof); ushort offset = member.offsetof;//cast(ushort)__traits(getMember, T, member).offsetof; - static if(__traits(isIntegral,member_type)) + static if(is(member_type == vec2)) + { + comp_edit.variables[comp_edit.used++] = VariableGUI(VariableGUI.Type.vec2,member_str,offset); + } + else static if(is(member_type == ivec2)) + { + comp_edit.variables[comp_edit.used++] = VariableGUI(VariableGUI.Type.ivec2,member_str,offset); + } + else static if(is(member_type == vec4)) + { + comp_edit.variables[comp_edit.used++] = VariableGUI(VariableGUI.Type.vec4,member_str,offset); + } + else static if(is(member_type == ivec4)) + { + comp_edit.variables[comp_edit.used++] = VariableGUI(VariableGUI.Type.ivec4,member_str,offset); + } + else static if(__traits(isIntegral,member_type)) { static if(__traits(isUnsigned, member_type)) { @@ -227,14 +247,15 @@ struct GUIManager { if(igCollapsingHeader("Systems", ImGuiTreeNodeFlags_SpanFullWidth | ImGuiTreeNodeFlags_DefaultOpen)) { - bool true_ = true; + //bool true_ = true; igIndent(8); foreach(ref SystemGUI system;systems) { if(igCheckbox(system.name,&system.enabled)) { - if(system.enabled)system.system.enable(); - else system.system.disable(); + System* sys = launcher.manager.getSystem(system.id); + if(system.enabled)sys.enable(); + else sys.disable(); } } igUnindent(8); @@ -347,6 +368,18 @@ struct GUIManager if(igColorEdit4(var.name, color.data, ImGuiColorEditFlags_None)) *cast(uint*)(data_ptr+var.offset) = colorVec4ToUint(color); break; + case VariableGUI.Type.vec2: + igDragFloat2(var.name, (cast(float*)(data_ptr+var.offset))[0..2], 0.1, -float.max, float.max, null, 1); + break; + case VariableGUI.Type.ivec2: + igDragInt2(var.name, (cast(int*)(data_ptr+var.offset))[0..2], 0.1, int.min, int.max, null); + break; + case VariableGUI.Type.vec4: + igDragFloat4(var.name, (cast(float*)(data_ptr+var.offset))[0..4], 0.1, -float.max, float.max, null, 1); + break; + case VariableGUI.Type.ivec4: + igDragInt4(var.name, (cast(int*)(data_ptr+var.offset))[0..4], 0.1, int.min, int.max, null); + break; default:break; } igPopID(); @@ -359,6 +392,7 @@ struct GUIManager void entityComponentsGUI() { + if(selected_template >= templates.length)return; EntityTemplate* tmpl = templates[selected_template].tmpl; EntityManager.EntityInfo* info = tmpl.info; foreach(comp_id; info.components) @@ -416,7 +450,7 @@ struct GUIManager if(igIsItemHovered(0))igSetTooltip("Select component to add/remove (SHIFT + Scroll)"); } style.Colors[ImGuiCol_Header] = col; - componentGUI(components[selected_component].component_id, components[selected_component].data); + if(selected_component < components.length)componentGUI(components[selected_component].component_id, components[selected_component].data); break; case Tool.selector: break;