diff --git a/demos/source/app.d b/demos/source/app.d index 9017f8d..ede93b5 100644 --- a/demos/source/app.d +++ b/demos/source/app.d @@ -96,6 +96,7 @@ struct Launcher void switchDemo(void function() start, bool function() loop, void function() end, void function(SDL_Event*) event, void function(vec2, Tool, int) tool, const (char)* tips) { gui_manager.clear(); + //launcher.ent if(this.end)this.end(); @@ -262,7 +263,7 @@ void mainLoop(void* arg) if(launcher.tool && launcher.tool_repeat != 0 && launcher.mouse.left && !igIsWindowHovered(ImGuiHoveredFlags_AnyWindow) && !igIsWindowFocused(ImGuiFocusedFlags_AnyWindow)) { float range = 500.0 / cast(float)launcher.tool_repeat; - launcher.repeat_time += launcher.delta_time * 100; + launcher.repeat_time += launcher.delta_time; while(launcher.repeat_time > range) { launcher.repeat_time -= range; @@ -463,7 +464,7 @@ void mainLoop(void* arg) if(launcher.show_demo_wnd) { igSetNextWindowPos(ImVec2(launcher.window_size.x - 260, 30), ImGuiCond_Once, ImVec2(0,0)); - igSetNextWindowSize(ImVec2(250, 250), ImGuiCond_Once); + igSetNextWindowSize(ImVec2(250, 500), ImGuiCond_Once); if(igBegin("Demo",&launcher.show_demo_wnd,0)) { ImDrawList* draw_list = igGetWindowDrawList(); @@ -745,8 +746,8 @@ int main(int argc, char** argv) { import demos.simple; import demos.space_invaders; - launcher.switchDemo(&spaceInvadersStart,&spaceInvadersLoop,&spaceInvadersEnd,&spaceInvadersEvent,&spaceInvadersTool,SpaceInvaders.tips); - // launcher.switchDemo(&simpleStart,&simpleLoop,&simpleEnd,&simpleEvent,&simpleTool,Simple.tips); + // launcher.switchDemo(&spaceInvadersStart,&spaceInvadersLoop,&spaceInvadersEnd,&spaceInvadersEvent,&spaceInvadersTool,SpaceInvaders.tips); + launcher.switchDemo(&simpleStart,&simpleLoop,&simpleEnd,&simpleEvent,&simpleTool,Simple.tips); } int key_num; diff --git a/demos/source/demos/chipmunk2d.d b/demos/source/demos/chipmunk2d.d deleted file mode 100644 index 96e5fa6..0000000 --- a/demos/source/demos/chipmunk2d.d +++ /dev/null @@ -1,19 +0,0 @@ -module demos.chipmunk2d; - -import app; - -import bindbc.sdl; - -import cimgui.cimgui; - -import bubel.ecs.attributes; -import bubel.ecs.core; -import bubel.ecs.entity; -import bubel.ecs.manager; -import bubel.ecs.std; - -import ecs_utils.gfx.texture; -import ecs_utils.math.vector; -import ecs_utils.utils; - -extern(C): \ No newline at end of file diff --git a/demos/source/demos/events.d b/demos/source/demos/events.d deleted file mode 100644 index 6215160..0000000 --- a/demos/source/demos/events.d +++ /dev/null @@ -1,19 +0,0 @@ -module demos.events; - -import app; - -import bindbc.sdl; - -import cimgui.cimgui; - -import bubel.ecs.attributes; -import bubel.ecs.core; -import bubel.ecs.entity; -import bubel.ecs.manager; -import bubel.ecs.std; - -import ecs_utils.gfx.texture; -import ecs_utils.math.vector; -import ecs_utils.utils; - -extern(C): \ No newline at end of file diff --git a/demos/source/demos/flag_component.d b/demos/source/demos/flag_component.d deleted file mode 100644 index 392164e..0000000 --- a/demos/source/demos/flag_component.d +++ /dev/null @@ -1,19 +0,0 @@ -module demos.flag_component; - -import app; - -import bindbc.sdl; - -import cimgui.cimgui; - -import bubel.ecs.attributes; -import bubel.ecs.core; -import bubel.ecs.entity; -import bubel.ecs.manager; -import bubel.ecs.std; - -import ecs_utils.gfx.texture; -import ecs_utils.math.vector; -import ecs_utils.utils; - -extern(C): \ No newline at end of file diff --git a/demos/source/demos/simple.d b/demos/source/demos/simple.d index 5e82d27..313cc00 100644 --- a/demos/source/demos/simple.d +++ b/demos/source/demos/simple.d @@ -52,7 +52,7 @@ struct DrawSystem struct EntitiesData { uint length; - uint thread_id; + //uint thread_id; uint job_id; @readonly CTexture[] textures; @readonly CLocation[] locations; diff --git a/demos/source/demos/snake.d b/demos/source/demos/snake.d index 50f7729..01e9a36 100644 --- a/demos/source/demos/snake.d +++ b/demos/source/demos/snake.d @@ -129,9 +129,10 @@ struct Snake } if(base_pos.x == random_pos.x && base_pos.y == random_pos.y)return; } - CILocation* location = apple_tmpl.getComponent!CILocation; - *location = random_pos; - Entity* apple = launcher.manager.addEntity(apple_tmpl); + //CILocation* location = apple_tmpl.getComponent!CILocation; + //*location = random_pos; + //Entity* apple = + launcher.manager.addEntity(apple_tmpl,[CILocation(random_pos).ref_].staticArray); } } @@ -366,8 +367,8 @@ struct MoveSystem mixin ECS.System!64; EntityTemplate* destroy_template; - CLocation* destroy_location; - CParticleVector* destroy_vector; + //CLocation* destroy_location; + //CParticleVector* destroy_vector; struct EntitiesData { @@ -381,8 +382,8 @@ struct MoveSystem void setTemplates() { destroy_template = snake.snake_destroy_particle; - destroy_location = destroy_template.getComponent!CLocation; - destroy_vector = destroy_template.getComponent!CParticleVector; + //destroy_location = destroy_template.getComponent!CLocation; + //destroy_vector = destroy_template.getComponent!CParticleVector; } void moveLocation(ref CILocation location, CMovement.Direction direction) @@ -436,24 +437,26 @@ struct MoveSystem case MapElement.Type.snake: foreach(loc; data.snakes[i].parts) { - destroy_location.x = loc.x * 16; - destroy_location.y = loc.y * 16; + //destroy_location.x = loc.x * 16; + //destroy_location.y = loc.y * 16; snake.element(MapElement(MapElement.Type.empty, EntityID()),loc); - launcher.manager.addEntity(snake.snake_destroy_particle); + launcher.manager.addEntity(snake.snake_destroy_particle,[CLocation(cast(vec2)(loc * 16)).ref_].staticArray); + + CLocation destroy_location; foreach(j;0..10) { destroy_location.x = loc.x * 16 + randomf() * 8 - 4; destroy_location.y = loc.y * 16 + randomf() * 8 - 4; - destroy_vector.velocity = vec2(randomf(),randomf())*0.4-0.2; + //destroy_vector.velocity = vec2(randomf(),randomf())*0.4-0.2; snake.element(MapElement(MapElement.Type.empty, EntityID()),loc); - launcher.manager.addEntity(snake.snake_destroy_particle); + launcher.manager.addEntity(snake.snake_destroy_particle, [destroy_location.ref_, CParticleVector(vec2(randomf(),randomf())*0.4-0.2).ref_].staticArray); } } - destroy_location.x = new_location.x * 16; - destroy_location.y = new_location.y * 16; + //destroy_location.x = new_location.x * 16; + //destroy_location.y = new_location.y * 16; snake.element(MapElement(MapElement.Type.empty, EntityID()),new_location); - launcher.manager.addEntity(snake.snake_destroy_particle); + launcher.manager.addEntity(snake.snake_destroy_particle,[CLocation(cast(vec2)(new_location * 16)).ref_].staticArray); launcher.manager.removeEntity(data.entities[i].id); break; @@ -796,9 +799,9 @@ void snakeStart() { ushort[4] components = [CILocation.component_id, CSnake.component_id, CMovement.component_id, CInput.component_id]; snake.snake_tmpl = launcher.manager.allocateTemplate(components); - CILocation* loc_comp = snake.snake_tmpl.getComponent!CILocation; - *loc_comp = ivec2(2,2); - launcher.manager.addEntity(snake.snake_tmpl); + //CILocation* loc_comp = snake.snake_tmpl.getComponent!CILocation; + //*loc_comp = ivec2(2,2); + launcher.manager.addEntity(snake.snake_tmpl,[CILocation(ivec2(2,2)).ref_].staticArray); } { @@ -846,15 +849,15 @@ void snakeTool(vec2 position, Tool tool, int size) CLocation* location = tmpl.getComponent!CLocation; if(location) { - position.x += (randomf - 0.5) * size; - position.y += (randomf - 0.5) * size; + position.x += (randomf() - 0.5) * size; + position.y += (randomf() - 0.5) * size; *location = position; } CILocation* ilocation = tmpl.getComponent!CILocation; if(ilocation) { - position.x += (randomf - 0.5) * size; - position.y += (randomf - 0.5) * size; + position.x += (randomf() - 0.5) * size; + position.y += (randomf() - 0.5) * size; ivec2 ipos; ipos.x = cast(int)(position.x / 16); ipos.y = cast(int)(position.y / 16); diff --git a/demos/source/demos/space_invaders.d b/demos/source/demos/space_invaders.d index c047d25..5615f0d 100644 --- a/demos/source/demos/space_invaders.d +++ b/demos/source/demos/space_invaders.d @@ -40,6 +40,7 @@ struct SpaceInvaders EntityTemplate* enemy_tmpl; EntityTemplate* ship_tmpl; EntityTemplate* laser_tmpl; + EntityTemplate*[5] bullet_tmpl; Texture texture; ShootGrid* shoot_grid; @@ -55,9 +56,13 @@ struct SpaceInvaders ~this() @nogc nothrow { if(shoot_grid)Mallocator.dispose(shoot_grid); - launcher.manager.freeTemplate(enemy_tmpl); - launcher.manager.freeTemplate(ship_tmpl); - launcher.manager.freeTemplate(laser_tmpl); + if(enemy_tmpl)launcher.manager.freeTemplate(enemy_tmpl); + if(ship_tmpl)launcher.manager.freeTemplate(ship_tmpl); + if(laser_tmpl)launcher.manager.freeTemplate(laser_tmpl); + foreach (EntityTemplate* tmpl; bullet_tmpl) + { + if(tmpl)launcher.manager.freeTemplate(tmpl); + } texture.destory(); } } @@ -115,7 +120,7 @@ struct CLocation alias value this; - vec2 value; + vec2 value = vec2(0); } struct CScale @@ -192,7 +197,7 @@ struct CGuild byte guild; } -struct CLaser +struct CBullet { mixin ECS.Component; @@ -408,12 +413,35 @@ struct CParticleEmitterTime { mixin ECS.Component; - float time; + float time = 0; } +///You can create separate component for every kind of spawned entities but it's not practial due to archetype fragmentation. +///Second approach can be commented code. It's gives good flexibility inchoosing entity, but it limits to one entity. +///Instead of entity it can be array of templates which is good solution, but if possibilities is known at time of game development it +///can be simply index/enum for type of spawn. Bad thing about this solution is problem witch merging multiple spawning types during +///gameplay, i.e. giving buff which cast firebols upon death. +struct CSpawnUponDeath +{ + mixin ECS.Component; + + enum Type + { + flashes_emitter, + } + + //EntityID parent; + //EntityTemplate* tmpl; + Type type; +} + +///This component can be replaced by "CSpawnUponDeath" but I want to gives possibility to add this component to every entity +///during gameplay. End application works exacly the same way for every demo so I can't use different way as adding component. struct CShootWaveUponDeath { mixin ECS.Component; + + CWeapon.Type bullet_type; } /*####################################################################################################################### @@ -604,7 +632,7 @@ struct ShootGridManager struct EntitiesData { uint length; - uint thread_id; + //uint thread_id; const (Entity)[] entity; @readonly CLocation[] locations; @readonly CShootGrid[] grid_flag; @@ -748,7 +776,8 @@ struct ShipWeaponSystem weapon_tmpl.getComponent!CTargetParent().rel_pos = vec2(0,0); weapon_tmpl.getComponent!CGuild().guild = 1; weapon_tmpl.getComponent!CScale().value = vec2(4,16); - weapon_tmpl.getComponent!CWeapon().level = 1; + //weapon_tmpl.getComponent!CWeapon().level = 1; + *weapon_tmpl.getComponent!CWeapon() = CWeapon(0,CWeapon.Type.canon,1); weapon_tmpl.getComponent!CDepth().depth = -1; weapon_tmpl.getComponent!CTexture().coords = vec4(136,96,4,16)*px; weapon_tmpl.getComponent!CWeaponLocation().rel_pos = vec2(0,12); @@ -801,7 +830,8 @@ struct ShipWeaponSystem [CHitMark.component_id, CHitPoints.component_id, CLocation.component_id, CTexture.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].staticArray + CChildren.component_id, CDepth.component_id, CTargetParent.component_id, + CSpawnUponDeath.component_id, CShootWaveUponDeath.component_id].staticArray ); CTexture* tex_comp = tower1_tmpl.getComponent!CTexture; @@ -813,6 +843,7 @@ struct ShipWeaponSystem tower1_tmpl.getComponent!CInit().type = CInit.Type.tower; tower1_tmpl.getComponent!CHitPoints().value = 10; tower1_tmpl.getComponent!CDepth().depth = -2; + tower1_tmpl.getComponent!CShootWaveUponDeath().bullet_type = CWeapon.Type.canon; tower1_tmpl.getComponent!CTargetParent().rel_pos = vec2(-33,2); tower2_tmpl = launcher.manager.allocateTemplate(tower1_tmpl); @@ -865,22 +896,12 @@ struct ShipWeaponSystem { foreach(i; 0..data.length) { - /*if(data.children[i].childern.length != 0)continue; - EntityID[3] weapons; - laser1_tmpl.getComponent!CTargetParent().parent = data.entity[i].id; - laser2_tmpl.getComponent!CTargetParent().parent = data.entity[i].id; - main_weapon_tmpl.getComponent!CTargetParent().parent = data.entity[i].id; - weapons[0] = launcher.manager.addEntity(laser1_tmpl).id; - weapons[1] = launcher.manager.addEntity(laser2_tmpl).id; - weapons[2] = launcher.manager.addEntity(main_weapon_tmpl).id; - data.children[i].childern = Mallocator.makeArray(weapons);*/ final switch(data.init[i].type) { case CInit.Type.space_ship:ship.add(&data.entity[i]);break; case CInit.Type.tower:tower.add(&data.entity[i]);break; case CInit.Type.boss:boss.add(&data.entity[i]);break; } - } } } @@ -942,7 +963,7 @@ struct DrawSystem struct EntitiesData { uint length; - uint thread_id; + //uint thread_id; uint job_id; @readonly CTexture[] textures; @readonly CLocation[] locations; @@ -1046,8 +1067,6 @@ struct LaserShootingSystem mixin ECS.System!32; bool shoot = false; - //static float[18] laser_shoot_times = [500,400,300,200,100,50,25,10,5,2,1,0.8,0.6,0.5,0.4,0.3,0.2,0.1]; - //static float[18] laser_shoot_disp = [0,0,0,0,0.05,0.06,0.08,0.1,0.14,0.18,0.2,0.25,0.26,0.27,0.28,0.29,0.3,0.4]; __gshared vec4[] fire_frames = [vec4(96,64,8,16)*px,vec4(104,64,8,16)*px,vec4(112,64,8,16)*px,vec4(120,64,8,16)*px,vec4(128,64,8,16)*px, vec4(136,64,8,16)*px,vec4(144,64,8,16)*px,vec4(152,64,8,16)*px,vec4(160,64,8,16)*px]; @@ -1055,16 +1074,10 @@ struct LaserShootingSystem // __gshared vec4[] fire_frames = [vec4(0,160,8,16)*px,vec4(16,160,16,16)*px,vec4(32,160,16,16)*px,vec4(48,160,16,16)*px,vec4(64,160,16,16)*px, // vec4(80,160,16,16)*px,vec4(96,160,16,16)*px,vec4(112,160,16,16)*px]; - /*CLocation* laser_location; - CVelocity* laser_velocity; - CGuild* laser_guild;*/ - struct EntitiesData { ///variable named "length" contain entites count uint length; - ///variable named "length" contain thread identifier - uint thread_id; CWeapon[] laser; @readonly CLocation[] location; @readonly CGuild[] guild; @@ -1076,77 +1089,53 @@ struct LaserShootingSystem @optional @readonly CRotation[] rotation; } - struct ThreadData - { - EntityTemplate* laser_tmpl; - CLocation* laser_location; - CVelocity* laser_velocity; - CGuild* laser_guild; + //EntityTemplate* laser_tmpl; + EntityTemplate* fire_tmpl; - EntityTemplate* fire_tmpl; - CLocation* fire_location; - CVelocity* fire_velocity; - CRotation* fire_rotation; - } - - ThreadData[] threads; + //EntityTemplate*[5] bullet_tmpl; ///Called inside "registerSystem" function void onCreate() { - threads = Mallocator.makeArray!ThreadData(32); - threads[0].laser_tmpl = launcher.manager.allocateTemplate( + /*bullet_tmpl[0] = launcher.manager.allocateTemplate( [CLocation.component_id, CTexture.component_id, CVelocity.component_id, - CScale.component_id, CLaser.component_id, CGuild.component_id].staticArray + CScale.component_id, CBullet.component_id, CGuild.component_id].staticArray ); + bullet_tmpl[0].getComponent!CTexture().coords = vec4(0,24,2,8)*px; + bullet_tmpl[0].getComponent!CScale().value = vec2(2,8); - CTexture* tex_comp = threads[0].laser_tmpl.getComponent!CTexture; - //tex_comp.tex = space_invaders.texture;//laser_tex; - tex_comp.coords = vec4(0*px,24*px,2*px,8*px); - CScale* scale_comp = threads[0].laser_tmpl.getComponent!CScale; - scale_comp.value = vec2(2,8); - threads[0].laser_location = threads[0].laser_tmpl.getComponent!CLocation; - threads[0].laser_velocity = threads[0].laser_tmpl.getComponent!CVelocity; - threads[0].laser_guild = threads[0].laser_tmpl.getComponent!CGuild; + bullet_tmpl[1] = launcher.manager.allocateTemplate(bullet_tmpl[0]); + bullet_tmpl[2] = launcher.manager.allocateTemplate(bullet_tmpl[0]); + bullet_tmpl[2].getComponent!CTexture().coords = vec4(64,32,8,16)*px; + bullet_tmpl[2].getComponent!CScale().value = vec2(8,16); + bullet_tmpl[3] = launcher.manager.allocateTemplate(bullet_tmpl[0]); + bullet_tmpl[3].getComponent!CTexture().coords = vec4(56,32,2,2)*px; + bullet_tmpl[3].getComponent!CScale().value = vec2(2,2); + // bullet_tmpl[3].getComponent!CTexture().coords = vec4(48,32,8,8)*px; + // bullet_tmpl[3].getComponent!CScale().value = vec2(8,8); + bullet_tmpl[4] = launcher.manager.allocateTemplate(bullet_tmpl[0]);*/ - threads[0].fire_tmpl = launcher.manager.allocateTemplate( + + fire_tmpl = launcher.manager.allocateTemplate( [CLocation.component_id, CTexture.component_id, CScale.component_id, CAnimation.component_id, CParticle.component_id, CRotation.component_id, CVelocity.component_id, CDamping.component_id].staticArray ); - tex_comp = threads[0].fire_tmpl.getComponent!CTexture; - //tex_comp.tex = space_invaders.texture;//laser_tex; - tex_comp.coords = vec4(96*px,64*px,8*px,16*px); - scale_comp = threads[0].fire_tmpl.getComponent!CScale; - scale_comp.value = vec2(8,16); - threads[0].fire_location = threads[0].fire_tmpl.getComponent!CLocation; - threads[0].fire_rotation = threads[0].fire_tmpl.getComponent!CRotation; - threads[0].fire_velocity = threads[0].fire_tmpl.getComponent!CVelocity; - threads[0].fire_tmpl.getComponent!(CParticle).life = 300; - *threads[0].fire_tmpl.getComponent!(CAnimation) = CAnimation(fire_frames, 0, 3); - - foreach(ref ThreadData thread;threads[1..$]) - { - thread.laser_tmpl = launcher.manager.allocateTemplate(threads[0].laser_tmpl); - thread.laser_location = thread.laser_tmpl.getComponent!CLocation; - thread.laser_velocity = thread.laser_tmpl.getComponent!CVelocity; - thread.laser_guild = thread.laser_tmpl.getComponent!CGuild; - thread.fire_tmpl = launcher.manager.allocateTemplate(threads[0].fire_tmpl); - thread.fire_location = thread.fire_tmpl.getComponent!CLocation; - thread.fire_rotation = thread.fire_tmpl.getComponent!CRotation; - thread.fire_velocity = thread.fire_tmpl.getComponent!CVelocity; - } - //laser_location = space_invaders.laser_tmpl.getComponent!CLocation; + fire_tmpl.getComponent!CTexture().coords = vec4(96,64,8,16)*px; + fire_tmpl.getComponent!CScale().value = vec2(8,16); + fire_tmpl.getComponent!(CParticle).life = 300; + *fire_tmpl.getComponent!(CAnimation) = CAnimation(fire_frames, 0, 3); } void onDestroy() { - foreach(ref ThreadData thread;threads[1..$]) + //launcher.manager.freeTemplate(laser_tmpl); + /*foreach (EntityTemplate* tmpl; bullet_tmpl) { - launcher.manager.freeTemplate(thread.laser_tmpl); - } - Mallocator.dispose(threads); + launcher.manager.freeTemplate(tmpl); + }*/ + launcher.manager.freeTemplate(fire_tmpl); } bool onBegin() @@ -1164,7 +1153,6 @@ struct LaserShootingSystem void onUpdate(EntitiesData data) { - ThreadData* thread = &threads[data.thread_id]; //conditional branch for whole entities block if(shoot || data.auto_shoot) { @@ -1174,58 +1162,65 @@ struct LaserShootingSystem laser.shoot_time += launcher.delta_time; while(laser.shoot_time > CWeapon.levels[laser.level - 1].reload_time) { + CVelocity laser_velocity; + CGuild laser_guild; + CLocation laser_location; + CVelocity fire_velocity; + CLocation fire_location; + CRotation fire_rotation; + laser.shoot_time -= CWeapon.levels[laser.level - 1].reload_time; - thread.laser_location.value = data.location[i]; + laser_location.value = data.location[i]; - thread.laser_velocity.value = vec2((randomf()*2-1) * CWeapon.levels[laser.level - 1].dispersion,1);//data.shoot_direction[i].direction == Direction.up ? 1.0 : -1.0); - if(data.shoot_direction && data.shoot_direction[i].direction == Direction.down)thread.laser_velocity.y = -1; + laser_velocity.value = vec2((randomf()*2-1) * CWeapon.levels[laser.level - 1].dispersion,1);//data.shoot_direction[i].direction == Direction.up ? 1.0 : -1.0); + if(data.shoot_direction && data.shoot_direction[i].direction == Direction.down)laser_velocity.y = -1; - thread.laser_guild.guild = data.guild[i].guild; + laser_guild.guild = data.guild[i].guild; - if(laser.level < 3)thread.laser_velocity.value = thread.laser_velocity.value * 0.4f; + if(laser.level < 3)laser_velocity.value = laser_velocity.value * 0.4f; if(data.velocity) { - thread.fire_velocity.value = data.velocity[i]; - //thread.laser_velocity.value += data.velocity[i] * 0.5; + fire_velocity.value = data.velocity[i]; + //laser_velocity.value += data.velocity[i] * 0.5; } - else thread.fire_velocity.value = vec2(0,0); + else fire_velocity.value = vec2(0,0); - thread.fire_location.value = data.location[i]; + fire_location.value = data.location[i]; if(data.shoot_direction[i].direction == Direction.down) { - thread.fire_rotation.value = PI; - //thread.fire_location.value.y -= 16; + fire_rotation.value = PI; + //fire_location.value.y -= 16; } else { - thread.fire_rotation.value = 0; - //thread.fire_location.value.y += 24; + fire_rotation.value = 0; + //fire_location.value.y += 24; } if(data.rotation) { float sinn = sinf(data.rotation[i]); float coss = cosf(data.rotation[i]); - float x = thread.laser_velocity.y*sinn + thread.laser_velocity.x*coss; - float y = thread.laser_velocity.y*coss + thread.laser_velocity.x*sinn; - thread.laser_velocity.value = vec2(x,y); - thread.fire_rotation.value = data.rotation[i]; + float x = laser_velocity.y*sinn + laser_velocity.x*coss; + float y = laser_velocity.y*coss + laser_velocity.x*sinn; + laser_velocity.value = vec2(x,y); + fire_rotation.value = data.rotation[i]; if(data.weapon_location) { vec2 rel_pos = vec2(data.weapon_location[i].rel_pos.y*sinn+data.weapon_location[i].rel_pos.x*coss, data.weapon_location[i].rel_pos.y*coss+data.weapon_location[i].rel_pos.x*sinn); - thread.laser_location.value += rel_pos; - thread.fire_location.value += rel_pos; + laser_location.value += rel_pos; + fire_location.value += rel_pos; } } else if(data.weapon_location) { - thread.laser_location.value += data.weapon_location[i].rel_pos; - thread.fire_location.value += data.weapon_location[i].rel_pos; + laser_location.value += data.weapon_location[i].rel_pos; + fire_location.value += data.weapon_location[i].rel_pos; } - launcher.manager.addEntity(thread.laser_tmpl); - launcher.manager.addEntity(thread.fire_tmpl); + launcher.manager.addEntity(space_invaders.bullet_tmpl[data.laser[i].type],[laser_velocity.ref_, laser_guild.ref_, laser_location.ref_].staticArray); + launcher.manager.addEntity(fire_tmpl,[fire_location.ref_, fire_rotation.ref_, fire_velocity.ref_].staticArray); } } } @@ -1287,7 +1282,7 @@ struct LaserCollisionSystem uint length; const (Entity)[] entity; @readonly CLocation[] location; - @readonly CLaser[] laser; + @readonly CBullet[] laser; @readonly CGuild[] guild; } @@ -1312,69 +1307,63 @@ struct ParticleEmittingSystem struct EntitiesData { uint length; - uint thread_id; + //uint thread_id; CParticleEmitterTime[] emit_time; @readonly CLocation[] location; @readonly CParticleEmitter[] emitter; @optional @readonly CVelocity[] velocity; + @optional @readonly CDepth[] depth; } + + __gshared vec4[] flashes = [vec4(224,0,16,16)*px,vec4(240,0,16,16)*px,vec4(256,0,16,16)*px,vec4(272,0,16,16)*px,vec4(288,0,16,16)*px, + vec4(304,0,16,16)*px,vec4(320,0,16,16)*px]; - struct Thread - { - EntityTemplate*[1] templates; - } - - Thread[] threads; + EntityTemplate*[1] templates; void onCreate() { - threads = Mallocator.makeArray!Thread(32); - - threads[0].templates[0] = launcher.manager.allocateTemplate( + templates[0] = launcher.manager.allocateTemplate( [CLocation.component_id, CTexture.component_id, CScale.component_id, CAnimation.component_id, CParticle.component_id, CRotation.component_id, - CVelocity.component_id, CDamping.component_id].staticArray); - - foreach(ref thread;threads[1 .. $]) - { - thread.templates[0] = launcher.manager.allocateTemplate(threads[0].templates[0]); - } + CVelocity.component_id, CDamping.component_id, CDepth.component_id].staticArray); + *templates[0].getComponent!CAnimation() = CAnimation(flashes,0,2); + *templates[0].getComponent!CParticle() = CParticle(350); + //*templates[0].getComponent!CDepth() = CDepth(-3); } void onDestroy() { - foreach(ref thread;threads[1 .. $]) + foreach(tmpl; templates) { - foreach(tmpl; thread.templates) - { - launcher.manager.freeTemplate(tmpl); - } - } - Mallocator.dispose(threads); + launcher.manager.freeTemplate(tmpl); + } } void onUpdate(EntitiesData data) { - Thread* thread = &threads[data.thread_id]; foreach(i;0..data.length) { data.emit_time[i].time -= launcher.delta_time; while(data.emit_time[i].time < 0) { + CVelocity velocity; + CDepth depth; + CParticleEmitter* emitter = &data.emitter[i]; data.emit_time[i].time += emitter.time_range.x + randomf() * emitter.time_range.y; - EntityTemplate* tmpl = thread.templates[emitter.tmpl_id]; - CLocation* location = tmpl.getComponent!CLocation; - if(location)location.value = data.location[i]; - if(data.velocity) { - CVelocity* velocity = tmpl.getComponent!CVelocity; - if(velocity)velocity.value = data.velocity[i]; + velocity.value = data.velocity[i]; } - launcher.manager.addEntity(tmpl); + + if(data.depth) + { + depth.depth = data.depth[i]; + } + + launcher.manager.addEntity(templates[0],[data.location[i].ref_,velocity.ref_,depth.ref_].staticArray); } } } @@ -1617,10 +1606,7 @@ struct HitPointsSystem __gshared vec4[] explosion_laser_frames = [vec4(80,128,16,16)*px,vec4(96,128,16,16)*px,vec4(112,128,16,16)*px,vec4(128,128,16,16)*px,vec4(144,128,16,16)*px,vec4(160,128,16,16)*px,vec4(176,128,16,16)*px,vec4(192,128,16,16)*px,vec4(208,128,16,16)*px]; EntityTemplate* upgrade_tmpl; - CLocation* upgrade_location; - EntityTemplate* explosion_tmpl; - CLocation* explosion_location; struct EntitiesData { @@ -1629,29 +1615,31 @@ struct HitPointsSystem void onCreate() { - upgrade_tmpl = launcher.manager.allocateTemplate([CVelocity.component_id, CLocation.component_id, CTexture.component_id, CScale.component_id, CUpgrade.component_id, CAnimation.component_id, CAnimationLooped.component_id].staticArray); - CTexture* tex_comp = upgrade_tmpl.getComponent!CTexture; + upgrade_tmpl = launcher.manager.allocateTemplate( + [CVelocity.component_id, CLocation.component_id, CTexture.component_id, + CScale.component_id, CUpgrade.component_id, CAnimation.component_id, + CAnimationLooped.component_id].staticArray); //tex_comp.tex = space_invaders.texture;//ship_tex; - tex_comp.coords = vec4(0*px,32*px,16*px,16*px); + upgrade_tmpl.getComponent!CTexture().coords = vec4(0*px,32*px,16*px,16*px); *upgrade_tmpl.getComponent!CAnimation = CAnimation(upgrade_laser_frames, 0, 1); - CVelocity* vel_comp = upgrade_tmpl.getComponent!CVelocity; - vel_comp.value = vec2(0,-0.1); - upgrade_location = upgrade_tmpl.getComponent!CLocation; + upgrade_tmpl.getComponent!CVelocity().value = vec2(0,-0.1); - explosion_tmpl = launcher.manager.allocateTemplate([CDepth.component_id, CParticle.component_id, CLocation.component_id, CTexture.component_id, CScale.component_id, CAnimation.component_id].staticArray); + explosion_tmpl = launcher.manager.allocateTemplate( + [CDepth.component_id, CParticle.component_id, CLocation.component_id, + CTexture.component_id, CScale.component_id, CAnimation.component_id].staticArray); //explosion_tmpl.getComponent!(CTexture).tex = space_invaders.texture; *explosion_tmpl.getComponent!CAnimation = CAnimation(explosion_laser_frames, 0, 1.333); explosion_tmpl.getComponent!(CParticle).life = 600; *explosion_tmpl.getComponent!CDepth = -1; - explosion_location = explosion_tmpl.getComponent!CLocation; } void onDestroy() { launcher.manager.freeTemplate(upgrade_tmpl); + launcher.manager.freeTemplate(explosion_tmpl); } - void handleEvent(Entity* entity, EDamage event) + /*void handleEvent(Entity* entity, EDamage event) { CHitPoints* hp = entity.getComponent!CHitPoints; if(*hp <= 0)return; @@ -1663,7 +1651,7 @@ struct HitPointsSystem } CHitMark* hit_mark = entity.getComponent!CHitMark; if(hit_mark)hit_mark.value = 127; - } + }*/ void handleEvent(Entity* entity, EBulletHit event) { @@ -1690,11 +1678,9 @@ struct HitPointsSystem { if(randomRange(0, 1000) < 5) { - *upgrade_location = *location; - launcher.manager.addEntity(upgrade_tmpl); + launcher.manager.addEntity(upgrade_tmpl,[location.ref_].staticArray); } - *explosion_location = *location; - launcher.manager.addEntity(explosion_tmpl); + launcher.manager.addEntity(explosion_tmpl,[location.ref_].staticArray); } } launcher.manager.removeEntity(entity.id); @@ -1720,6 +1706,55 @@ struct ChildDestroySystem } } +struct ShootWaveSystem +{ + mixin ECS.System; + + struct EntitiesData + { + CLocation[] location; + CShootWaveUponDeath[] shoot_wave; + } + + vec2[] dirs; + + void onCreate() + { + enum count = 24; + dirs = Mallocator.makeArray!vec2(count); + float step = 2 * PI / cast(float)count; + foreach(i;0..count) + { + float angle = step * i; + dirs[i] = vec2(sinf(angle),cosf(angle)) * 0.2; + } + } + + void onDestroy() + { + Mallocator.dispose(dirs); + } + + void handleEvent(Entity* entity, EDeath event) + { + + CShootWaveUponDeath* wave = entity.getComponent!CShootWaveUponDeath; + CLocation* location = entity.getComponent!CLocation; + CGuild* guild = entity.getComponent!CGuild; + + //LaserShootingSystem.bullet_tmpl + EntityTemplate* tmpl = space_invaders.bullet_tmpl[wave.bullet_type]; + foreach(dir;dirs) + { + if(guild)launcher.manager.addEntity(tmpl,[location.ref_,guild.ref_,CVelocity(dir).ref_].staticArray); + else launcher.manager.addEntity(tmpl,[location.ref_,CVelocity(dir).ref_].staticArray); + } + //launcher.manager.addEntity(tmpl);//,[location.ref_].staticArray); + + //launcher.manager.addEntity(space_invaders.bullet_tmpl[0]); + } +} + struct PartsDestroySystem { mixin ECS.System; @@ -1738,9 +1773,14 @@ struct PartsDestroySystem flashes_emitter = launcher.manager.allocateTemplate( [ CVelocity.component_id, CLocation.component_id, CParticleEmitter.component_id, - CParticleEmitterTime.component_id, CTargetParent.component_id + CParticleEmitterTime.component_id, CTargetParent.component_id, CDepth.component_id ].staticArray); - *flashes_emitter.getComponent!CParticleEmitter() = CParticleEmitter(vec2(0,0), vec2(400,400), 0); + *flashes_emitter.getComponent!CParticleEmitter() = CParticleEmitter(vec2(0,0), vec2(800,1600), 0); + } + + void onDestroy() + { + launcher.manager.freeTemplate(flashes_emitter); } void handleEvent(Entity* entity, EDestroyedChild event) @@ -1752,17 +1792,24 @@ struct PartsDestroySystem if(init.type == CInit.Type.boss) { CChildren* children = entity.getComponent!CChildren; - foreach(EntityID child; children.childern) + foreach(ref EntityID child; children.childern) { if(child == event.id) { Entity* child_entity = launcher.manager.getEntity(child); if(child_entity) { + CLocation location; CTargetParent* target_parent = child_entity.getComponent!CTargetParent; + CDepth* target_depth = child_entity.getComponent!CDepth; + CLocation* target_location = child_entity.getComponent!CLocation; + //CVelocity* velocity = child_entity.getComponent!CTargetParent; + + if(target_location)location = *target_location; *flashes_emitter.getComponent!CTargetParent() = *target_parent; - launcher.manager.addEntity(flashes_emitter); + if(target_depth)child = launcher.manager.addEntity(flashes_emitter, [target_depth.ref_, location.ref_].staticArray).id; + else child = launcher.manager.addEntity(flashes_emitter, [location.ref_].staticArray).id; } break; } @@ -1793,7 +1840,7 @@ struct ClampPositionSystem @optional @readonly CColliderScale[] collider_scale; @optional @readonly CScale[] scale; - @optional const (CLaser)[] laser; + @optional const (CBullet)[] laser; @optional const (CUpgrade)[] upgrade; //@optional CVelocity[] velocity; //@optional const (CSideMove)[] side_move; @@ -1891,7 +1938,7 @@ struct MovementSystem const (CVelocity)[] velocity; //components are treated as required by default CLocation[] locations; - //@optional const (CLaser)[] laser; + //@optional const (CBullet)[] laser; const (Entity)[] entities; //@optional CSideMove[] side_move; @@ -1927,8 +1974,10 @@ struct AnimationSystem foreach(i;0..data.length) { data.animation[i].time += dt * data.animation[i].speed; - while(data.animation[i].time >= data.animation[i].frames.length)data.animation[i].time -= cast(float)data.animation[i].frames.length; - data.texture[i].coords = data.animation[i].frames[cast(int)(data.animation[i].time)]; + while(cast(uint)data.animation[i].time >= data.animation[i].frames.length)data.animation[i].time -= cast(float)data.animation[i].frames.length; + if(cast(uint)(data.animation[i].time) >= data.animation[i].frames.length)assert(0); + uint index = cast(uint)(data.animation[i].time); + if(index < data.animation[i].frames.length)data.texture[i].coords = data.animation[i].frames[index]; } } else @@ -1936,8 +1985,9 @@ struct AnimationSystem foreach(i;0..data.length) { data.animation[i].time += dt * data.animation[i].speed; - if(data.animation[i].time >= data.animation[i].frames.length)data.animation[i].time = data.animation[i].frames.length - 0.1; - data.texture[i].coords = data.animation[i].frames[cast(int)(data.animation[i].time)]; + if(cast(uint)data.animation[i].time >= data.animation[i].frames.length)data.animation[i].time = data.animation[i].frames.length - 0.9; + uint index = cast(uint)(data.animation[i].time); + if(index < data.animation[i].frames.length)data.texture[i].coords = data.animation[i].frames[index]; } } @@ -2070,6 +2120,66 @@ struct CShipIterator } } +/*struct SpawnUponDeathSystem +{ + mixin ECS.System; + + struct EntitiesData + { + @readonly CSpawnUponDeath[] spawn; + @optional CTargetParent[] parent; + } + + EntityTemplate* flashes_emitter; + + void onCreate() + { + flashes_emitter = launcher.manager.allocateTemplate( + [ + CVelocity.component_id, CLocation.component_id, CParticleEmitter.component_id, + CParticleEmitterTime.component_id, CTargetParent.component_id + ].staticArray); + *flashes_emitter.getComponent!CParticleEmitter() = CParticleEmitter(vec2(0,0), vec2(400,400), 0); + } + + void onDestroy() + { + launcher.manager.freeTemplate(flashes_emitter); + } + + void onRemoveEntity(EntitiesData data) + { + //CSpawnUponDeath[] spawn = + switch(data.spawn[0].type) + { + case CSpawnUponDeath.Type.flashes_emitter: + if(data.parent) + { + /*Entity* parent_entity = launcher.manager.getEntity(data.parent[0].parent); + CChildren* children = entity.getComponent!CChildren; + foreach(ref EntityID child; children.childern) + { + if(child == event.id) + { + Entity* child_entity = launcher.manager.getEntity(child); + if(child_entity) + { + *flashes_emitter.getComponent!CTargetParent = data.parent[0]; + launcher.manager.addEntity(flashes_emitter); + //child = launcher.manager.addEntity(flashes_emitter); + } + break; + } + } + } + break; + default:break; + } + } + + //void handleEvent(Entity* entity, ) +}//*/ + extern(C) float sqrtf(float x) @nogc nothrow @system; extern(C) float acosf(float x) @nogc nothrow @system; extern(C) float sinf(float x) @nogc nothrow @system; @@ -2198,7 +2308,7 @@ void spaceInvadersStart() launcher.manager.registerComponent!CAutoShoot; launcher.manager.registerComponent!CWeapon; launcher.manager.registerComponent!CVelocity; - launcher.manager.registerComponent!CLaser; + launcher.manager.registerComponent!CBullet; launcher.manager.registerComponent!CSideMove; launcher.manager.registerComponent!CDepth; launcher.manager.registerComponent!CShootGrid; @@ -2223,6 +2333,8 @@ void spaceInvadersStart() launcher.manager.registerComponent!CColliderScale; launcher.manager.registerComponent!CParticleEmitter; launcher.manager.registerComponent!CParticleEmitterTime; + launcher.manager.registerComponent!CSpawnUponDeath; + launcher.manager.registerComponent!CShootWaveUponDeath; launcher.manager.registerEvent!EChangeDirection; launcher.manager.registerEvent!EDamage; @@ -2248,16 +2360,17 @@ void spaceInvadersStart() launcher.manager.registerSystem!ParticleSystem(-100); launcher.manager.registerSystem!AnimationSystem(-100); launcher.manager.registerSystem!DampingSystem(-101); - launcher.manager.registerSystem!MoveToParentTargetSystem(99); + launcher.manager.registerSystem!MoveToParentTargetSystem(-98); launcher.manager.registerSystem!ParentOwnerSystem(-101); launcher.manager.registerSystem!ShipWeaponSystem(-100); - launcher.manager.registerSystem!ParticleEmittingSystem(-100); - + launcher.manager.registerSystem!ParticleEmittingSystem(-95); launcher.manager.registerSystem!RotateToTargetSystem(-100); launcher.manager.registerSystem!ShipTargetSystem(-110); launcher.manager.registerSystem!CShipIterator(-100); launcher.manager.registerSystem!PartsDestroySystem(-80); launcher.manager.registerSystem!ChildDestroySystem(-110); + launcher.manager.registerSystem!ShootWaveSystem(-100); + //launcher.manager.registerSystem!SpawnUponDeathSystem(-110); launcher.manager.endRegister(); @@ -2267,19 +2380,26 @@ void spaceInvadersStart() launcher.gui_manager.addSystem(MovementSystem.system_id,"Movement System"); launcher.gui_manager.addSystem(ClampPositionSystem.system_id,"Clamp Position System"); launcher.gui_manager.addSystem(ChangeDirectionSystem.system_id,"Change Direction System"); - launcher.gui_manager.addSystem(LaserCollisionSystem.system_id,"Draw System"); + launcher.gui_manager.addSystem(LaserCollisionSystem.system_id,"Laser Collision System"); launcher.gui_manager.addSystem(ShootGridManager.system_id,"Shoot Grid Manager"); launcher.gui_manager.addSystem(ShootGridCleaner.system_id,"Shoot Grid Cleaner"); launcher.gui_manager.addSystem(HitPointsSystem.system_id,"Hit Points System"); - launcher.gui_manager.addSystem(HitMarkingSystem.system_id,"Hit Matking System"); + launcher.gui_manager.addSystem(HitMarkingSystem.system_id,"Hit Marking System"); launcher.gui_manager.addSystem(UpgradeCollisionSystem.system_id,"Upgrade Collision System"); launcher.gui_manager.addSystem(UpgradeSystem.system_id,"Upgrade System"); launcher.gui_manager.addSystem(ParticleSystem.system_id,"Particle System"); launcher.gui_manager.addSystem(AnimationSystem.system_id,"Animation System"); launcher.gui_manager.addSystem(DampingSystem.system_id,"Damping System"); launcher.gui_manager.addSystem(MoveToParentTargetSystem.system_id,"Move To Target System"); - launcher.gui_manager.addSystem(ParentOwnerSystem.system_id,"Parent Owner System System"); + launcher.gui_manager.addSystem(ParentOwnerSystem.system_id,"Parent Owner System"); launcher.gui_manager.addSystem(ShipWeaponSystem.system_id,"Ship Weapon System"); + launcher.gui_manager.addSystem(ParticleEmittingSystem.system_id,"Particle Emitting System"); + launcher.gui_manager.addSystem(RotateToTargetSystem.system_id,"Rotate To Target System"); + launcher.gui_manager.addSystem(ShipTargetSystem.system_id,"Ship Target System"); + launcher.gui_manager.addSystem(PartsDestroySystem.system_id,"Parts Destroy System"); + launcher.gui_manager.addSystem(ChildDestroySystem.system_id,"Child Destroy System"); + launcher.gui_manager.addSystem(ShootWaveSystem.system_id,"Shoot Wave System"); + //launcher.gui_manager.addSystem(SpawnUponDeathSystem.system_id,"Child Destroy System"); //launcher.manager.getSystem(CleanSystem.system_id).disable(); { @@ -2290,30 +2410,23 @@ void spaceInvadersStart() CShootDirection.component_id, CShootGrid.component_id, CGuild.component_id, CDamping.component_id, CChildren.component_id, CInit.component_id].staticArray ); - //CWeapon* weapon = space_invaders.ship_tmpl.getComponent!CWeapon; - //weapon.level = 3; - space_invaders.ship_tmpl.getComponent!CTexture().coords = vec4(0*px,80*px,48*px,32*px); + space_invaders.ship_tmpl.getComponent!CTexture().coords = vec4(0,80,48,32)*px; space_invaders.ship_tmpl.getComponent!CScale().value = vec2(48,32); - space_invaders.ship_tmpl.getComponent!CLocation().value = vec2(64,64); space_invaders.ship_tmpl.getComponent!CHitPoints().value = 1000; space_invaders.ship_tmpl.getComponent!CDamping().value = 7; space_invaders.ship_tmpl.getComponent!CInit().type = CInit.Type.space_ship; space_invaders.ship_tmpl.getComponent!CColliderScale().value = vec2(26,24); - launcher.manager.addEntity(space_invaders.ship_tmpl); + launcher.manager.addEntity(space_invaders.ship_tmpl,[CLocation(vec2(64,64)).ref_].staticArray); } { - ushort[6] components = [CLocation.component_id, CTexture.component_id, CVelocity.component_id, CScale.component_id, CLaser.component_id, CGuild.component_id]; + ushort[6] components = [CLocation.component_id, CTexture.component_id, CVelocity.component_id, CScale.component_id, CBullet.component_id, CGuild.component_id]; space_invaders.laser_tmpl = launcher.manager.allocateTemplate(components); - CTexture* tex_comp = space_invaders.laser_tmpl.getComponent!CTexture; - //tex_comp.tex = 0;//space_invaders.texture;//laser_tex; - tex_comp.coords = vec4(0*px,24*px,2*px,8*px); - CScale* scale_comp = space_invaders.laser_tmpl.getComponent!CScale; - scale_comp.value = vec2(2,8); - CVelocity* vel_comp = space_invaders.laser_tmpl.getComponent!CVelocity; - vel_comp.value = vec2(0,1); + space_invaders.laser_tmpl.getComponent!CTexture().coords = vec4(0,24,2,8)*px; + space_invaders.laser_tmpl.getComponent!CScale().value = vec2(2,8); + space_invaders.laser_tmpl.getComponent!CVelocity().value = vec2(0,1); } EntityTemplate* enemy_tmpl; @@ -2333,11 +2446,12 @@ void spaceInvadersStart() CDepth.component_id].staticArray ); - CTexture* tex_comp = boss_tmpl.getComponent!CTexture; + //CTexture* tex_comp = boss_tmpl.getComponent!CTexture; //tex_comp.tex = space_invaders.texture;//ship_tex; - tex_comp.coords = vec4(128*px,0*px,96*px,48*px); - CLocation* loc_comp = boss_tmpl.getComponent!CLocation; - loc_comp.value = vec2(64,space_invaders.map_size.y - 16); + //tex_comp.coords = vec4(128*px,0*px,96*px,48*px); + //CLocation* loc_comp = boss_tmpl.getComponent!CLocation; + //loc_comp.value = vec2(64,space_invaders.map_size.y - 16); + boss_tmpl.getComponent!CTexture().coords = vec4(128,0,96,48)*px; boss_tmpl.getComponent!CGuild().guild = 1; boss_tmpl.getComponent!CInit().type = CInit.Type.boss; boss_tmpl.getComponent!CScale().value = vec2(96,48); @@ -2354,11 +2468,7 @@ void spaceInvadersStart() CChildren.component_id].staticArray ); - CTexture* tex_comp = tower_tmpl.getComponent!CTexture; - //tex_comp.tex = space_invaders.texture;//ship_tex; - tex_comp.coords = vec4(96*px,96*px,16*px,16*px); - CLocation* loc_comp = tower_tmpl.getComponent!CLocation; - loc_comp.value = vec2(64,space_invaders.map_size.y - 16); + tower_tmpl.getComponent!CTexture().coords = vec4(96,96,16,16)*px; tower_tmpl.getComponent!CGuild().guild = 1; tower_tmpl.getComponent!CInit().type = CInit.Type.tower; tower_tmpl.getComponent!CHitPoints().value = 10; @@ -2373,35 +2483,29 @@ void spaceInvadersStart() CGuild.component_id].staticArray ); - CTexture* tex_comp = space_invaders.enemy_tmpl.getComponent!CTexture; - //tex_comp.tex = space_invaders.texture;//ship_tex; - tex_comp.coords = vec4(32*px,32*px,16*px,16*px); - CLocation* loc_comp = space_invaders.enemy_tmpl.getComponent!CLocation; - loc_comp.value = vec2(64,space_invaders.map_size.y - 16); - CShootDirection* shoot_dir_comp = space_invaders.enemy_tmpl.getComponent!CShootDirection; - shoot_dir_comp.direction = Direction.down; - CVelocity* vel_comp = space_invaders.enemy_tmpl.getComponent!CVelocity; - vel_comp.value = vec2(0.1,0); + space_invaders.enemy_tmpl.getComponent!CTexture().coords = vec4(32,32,16,16)*px; + space_invaders.enemy_tmpl.getComponent!CShootDirection().direction = Direction.down; + space_invaders.enemy_tmpl.getComponent!CVelocity().value = vec2(0.1,0); space_invaders.enemy_tmpl.getComponent!CGuild().guild = 1; space_invaders.enemy_tmpl.getComponent!CWeaponLocation().rel_pos = vec2(0,-15); Entity* current_entity; - current_entity = launcher.manager.addEntity(space_invaders.enemy_tmpl); + current_entity = launcher.manager.addEntity(space_invaders.enemy_tmpl,[CLocation(vec2(32,space_invaders.map_size.y - 16)).ref_].staticArray); launcher.manager.addComponents(current_entity.id,CSideMove(0)); - loc_comp.value = vec2(128,space_invaders.map_size.y - 16); - current_entity = launcher.manager.addEntity(space_invaders.enemy_tmpl); + //loc_comp.value = vec2(128,space_invaders.map_size.y - 16); + current_entity = launcher.manager.addEntity(space_invaders.enemy_tmpl,[CLocation(vec2(128,space_invaders.map_size.y - 16)).ref_].staticArray); launcher.manager.addComponents(current_entity.id,CSideMove(-1)); enemy_id = current_entity.id; //enemy_tmpl = launcher.manager.allocateTemplate(current_entity.id); - loc_comp.value = vec2(256,space_invaders.map_size.y - 16); - launcher.manager.addEntity(space_invaders.enemy_tmpl); + //loc_comp.value = vec2(256,space_invaders.map_size.y - 16); + launcher.manager.addEntity(space_invaders.enemy_tmpl,[CLocation(vec2(256,space_invaders.map_size.y - 16)).ref_].staticArray); - loc_comp.value = vec2(0,space_invaders.map_size.y - 16); - current_entity = launcher.manager.addEntity(space_invaders.enemy_tmpl); + //loc_comp.value = vec2(0,space_invaders.map_size.y - 16); + current_entity = launcher.manager.addEntity(space_invaders.enemy_tmpl,[CLocation(vec2(0,space_invaders.map_size.y - 16)).ref_].staticArray); launcher.manager.addComponents(current_entity.id,CSideMove(0)); grouped_id = current_entity.id; @@ -2412,11 +2516,8 @@ void spaceInvadersStart() { upgrade_tmpl = launcher.manager.allocateTemplate([CVelocity.component_id, CLocation.component_id, CTexture.component_id, CScale.component_id, CUpgrade.component_id, CAnimationLooped.component_id, CAnimation.component_id].staticArray); - CTexture* tex_comp = upgrade_tmpl.getComponent!CTexture; - //tex_comp.tex = space_invaders.texture;//ship_tex; - tex_comp.coords = vec4(0*px,32*px,16*px,16*px); - CVelocity* vel_comp = upgrade_tmpl.getComponent!CVelocity; - vel_comp.value = vec2(0,-0.1); + upgrade_tmpl.getComponent!CTexture().coords = vec4(0,32,16,16)*px; + upgrade_tmpl.getComponent!CVelocity().value = vec2(0,-0.1); *upgrade_tmpl.getComponent!CAnimation = CAnimation(HitPointsSystem.upgrade_laser_frames, 0, 0.75); } @@ -2425,6 +2526,24 @@ void spaceInvadersStart() enemy_tmpl = launcher.manager.allocateTemplate(enemy_id); grouped_tmpl = launcher.manager.allocateTemplate(grouped_id); + space_invaders.bullet_tmpl[0] = launcher.manager.allocateTemplate( + [CLocation.component_id, CTexture.component_id, CVelocity.component_id, + CScale.component_id, CBullet.component_id, CGuild.component_id].staticArray + ); + space_invaders.bullet_tmpl[0].getComponent!CTexture().coords = vec4(0,24,2,8)*px; + space_invaders.bullet_tmpl[0].getComponent!CScale().value = vec2(2,8); + + space_invaders.bullet_tmpl[1] = launcher.manager.allocateTemplate(space_invaders.bullet_tmpl[0]); + space_invaders.bullet_tmpl[2] = launcher.manager.allocateTemplate(space_invaders.bullet_tmpl[0]); + space_invaders.bullet_tmpl[2].getComponent!CTexture().coords = vec4(64,32,8,16)*px; + space_invaders.bullet_tmpl[2].getComponent!CScale().value = vec2(8,16); + space_invaders.bullet_tmpl[3] = launcher.manager.allocateTemplate(space_invaders.bullet_tmpl[0]); + space_invaders.bullet_tmpl[3].getComponent!CTexture().coords = vec4(56,32,2,2)*px; + space_invaders.bullet_tmpl[3].getComponent!CScale().value = vec2(2,2); + // bullet_tmpl[3].getComponent!CTexture().coords = vec4(48,32,8,8)*px; + // bullet_tmpl[3].getComponent!CScale().value = vec2(8,8); + space_invaders.bullet_tmpl[4] = launcher.manager.allocateTemplate(space_invaders.bullet_tmpl[0]); + launcher.gui_manager.addTemplate(enemy_tmpl,"Enemy"); launcher.gui_manager.addTemplate(grouped_tmpl,"Grouped enemy"); launcher.gui_manager.addTemplate(launcher.manager.allocateTemplate(space_invaders.ship_tmpl),"Ship"); @@ -2432,6 +2551,9 @@ void spaceInvadersStart() launcher.gui_manager.addTemplate(upgrade_tmpl,"Upgrade"); launcher.gui_manager.addTemplate(tower_tmpl,"Tower"); launcher.gui_manager.addTemplate(boss_tmpl,"Boss"); + launcher.gui_manager.addTemplate(launcher.manager.allocateTemplate(space_invaders.bullet_tmpl[3]),"Cannon bullet"); + //launcher.gui_manager.addTemplate(launcher.manager.allocateTemplate(space_invaders.bullet_tmpl[4]),"Laser"); + //launcher.gui_manager.addTemplate(launcher.manager.allocateTemplate(space_invaders.bullet_tmpl[5]),"Laser"); } void spaceInvadersEnd() @@ -2445,6 +2567,7 @@ void spaceInvadersEnd() //launcher.manager.freeTemplate(space_invaders.enemy_tmpl); Mallocator.dispose(space_invaders); + space_invaders = null; } void spaceInvadersTool(vec2 position, Tool tool, int size) diff --git a/demos/source/gui/manager.d b/demos/source/gui/manager.d index 185fcd1..4d452ad 100644 --- a/demos/source/gui/manager.d +++ b/demos/source/gui/manager.d @@ -30,6 +30,7 @@ struct GUIManager systems.clear(); templates.clear(); + selected_tempalte = 0; } EntityTemplate* getSelectedTemplate()