Make common draw system, moved some components to basic components and fixed bug with GUI for signed short integers
This commit is contained in:
parent
3a7a5b2a21
commit
d733bb514c
5 changed files with 326 additions and 86 deletions
|
|
@ -35,13 +35,6 @@ private enum float px = 1.0/512.0;
|
||||||
alias location this;
|
alias location this;
|
||||||
|
|
||||||
vec2 location;
|
vec2 location;
|
||||||
}*/
|
|
||||||
|
|
||||||
struct CTexCoords
|
|
||||||
{
|
|
||||||
mixin ECS.Component;
|
|
||||||
|
|
||||||
vec4 value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct CColor
|
struct CColor
|
||||||
|
|
@ -53,6 +46,13 @@ struct CColor
|
||||||
@GUIColor uint value = uint.max;
|
@GUIColor uint value = uint.max;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct CTexCoords
|
||||||
|
{
|
||||||
|
mixin ECS.Component;
|
||||||
|
|
||||||
|
vec4 value;
|
||||||
|
}*/
|
||||||
|
|
||||||
struct CVelocity
|
struct CVelocity
|
||||||
{
|
{
|
||||||
mixin ECS.Component;
|
mixin ECS.Component;
|
||||||
|
|
@ -453,7 +453,7 @@ void particlesStart()
|
||||||
launcher.manager.beginRegister();
|
launcher.manager.beginRegister();
|
||||||
|
|
||||||
launcher.manager.registerComponent!CLocation;
|
launcher.manager.registerComponent!CLocation;
|
||||||
launcher.manager.registerComponent!CTexCoords;
|
//launcher.manager.registerComponent!CTexCoords;
|
||||||
launcher.manager.registerComponent!CColor;
|
launcher.manager.registerComponent!CColor;
|
||||||
launcher.manager.registerComponent!CVelocity;
|
launcher.manager.registerComponent!CVelocity;
|
||||||
launcher.manager.registerComponent!CAttractor;
|
launcher.manager.registerComponent!CAttractor;
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ import ecs_utils.math.vector;
|
||||||
import ecs_utils.utils;
|
import ecs_utils.utils;
|
||||||
|
|
||||||
import game_core.basic;
|
import game_core.basic;
|
||||||
|
import game_core.rendering;
|
||||||
|
|
||||||
//import std.math : PI;
|
//import std.math : PI;
|
||||||
|
|
||||||
|
|
@ -122,7 +123,7 @@ enum Direction : byte
|
||||||
alias value this;
|
alias value this;
|
||||||
|
|
||||||
vec2 value = vec2(0);
|
vec2 value = vec2(0);
|
||||||
}*/
|
}
|
||||||
|
|
||||||
struct CScale
|
struct CScale
|
||||||
{
|
{
|
||||||
|
|
@ -134,13 +135,13 @@ struct CScale
|
||||||
vec2 value = vec2(16,16);
|
vec2 value = vec2(16,16);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct CColliderScale
|
struct CDepth
|
||||||
{
|
{
|
||||||
mixin ECS.Component;
|
mixin ECS.Component;
|
||||||
|
|
||||||
alias value this;
|
alias depth this;
|
||||||
|
|
||||||
vec2 value = vec2(16,16);
|
short depth;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct CRotation
|
struct CRotation
|
||||||
|
|
@ -160,6 +161,15 @@ struct CTexture
|
||||||
//Texture tex;
|
//Texture tex;
|
||||||
uint id;
|
uint id;
|
||||||
vec4 coords = vec4(0,0,0,1);
|
vec4 coords = vec4(0,0,0,1);
|
||||||
|
}*/
|
||||||
|
|
||||||
|
struct CColliderScale
|
||||||
|
{
|
||||||
|
mixin ECS.Component;
|
||||||
|
|
||||||
|
alias value this;
|
||||||
|
|
||||||
|
vec2 value = vec2(16,16);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct CVelocity
|
struct CVelocity
|
||||||
|
|
@ -255,15 +265,6 @@ struct CSideMove
|
||||||
byte group = -1;
|
byte group = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct CDepth
|
|
||||||
{
|
|
||||||
mixin ECS.Component;
|
|
||||||
|
|
||||||
alias depth this;
|
|
||||||
|
|
||||||
short depth;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct CShootGrid
|
struct CShootGrid
|
||||||
{
|
{
|
||||||
mixin ECS.Component;
|
mixin ECS.Component;
|
||||||
|
|
@ -754,11 +755,11 @@ struct ShipWeaponSystem
|
||||||
CDepth* depth = entity.getComponent!CDepth;
|
CDepth* depth = entity.getComponent!CDepth;
|
||||||
EntityID[2] weapons;
|
EntityID[2] weapons;
|
||||||
weapon_tmpl.getComponent!CTargetParent().parent = entity.id;
|
weapon_tmpl.getComponent!CTargetParent().parent = entity.id;
|
||||||
if(depth)weapon_tmpl.getComponent!CDepth().depth = cast(short)(depth.depth - 1);
|
if(depth)weapon_tmpl.getComponent!CDepth().value = cast(short)(depth.value - 1);
|
||||||
else weapon_tmpl.getComponent!CDepth().depth = -1;
|
else weapon_tmpl.getComponent!CDepth().value = -1;
|
||||||
top_tmpl.getComponent!CTargetParent().parent = entity.id;
|
top_tmpl.getComponent!CTargetParent().parent = entity.id;
|
||||||
if(depth)top_tmpl.getComponent!CDepth().depth = cast(short)(depth.depth - 2);
|
if(depth)top_tmpl.getComponent!CDepth().value = cast(short)(depth.value - 2);
|
||||||
else top_tmpl.getComponent!CDepth().depth = -2;
|
else top_tmpl.getComponent!CDepth().value = -2;
|
||||||
|
|
||||||
weapons[0] = launcher.manager.addEntity(weapon_tmpl).id;
|
weapons[0] = launcher.manager.addEntity(weapon_tmpl).id;
|
||||||
weapons[1] = launcher.manager.addEntity(top_tmpl).id;
|
weapons[1] = launcher.manager.addEntity(top_tmpl).id;
|
||||||
|
|
@ -771,7 +772,7 @@ struct ShipWeaponSystem
|
||||||
[CWeapon.component_id, CLocation.component_id, CShootDirection.component_id,
|
[CWeapon.component_id, CLocation.component_id, CShootDirection.component_id,
|
||||||
CTargetParent.component_id, CGuild.component_id, CVelocity.component_id,
|
CTargetParent.component_id, CGuild.component_id, CVelocity.component_id,
|
||||||
CAutoShoot.component_id, CTarget.component_id, CTargetPlayerShip.component_id,
|
CAutoShoot.component_id, CTarget.component_id, CTargetPlayerShip.component_id,
|
||||||
CRotation.component_id, CScale.component_id, CTexture.component_id,
|
CRotation.component_id, CScale.component_id, CTexCoords.component_id,
|
||||||
CDepth.component_id, CWeaponLocation.component_id].staticArray);
|
CDepth.component_id, CWeaponLocation.component_id].staticArray);
|
||||||
*weapon_tmpl.getComponent!CWeapon = CWeapon(0,CWeapon.Type.laser,3);
|
*weapon_tmpl.getComponent!CWeapon = CWeapon(0,CWeapon.Type.laser,3);
|
||||||
weapon_tmpl.getComponent!CTargetParent().rel_pos = vec2(0,0);
|
weapon_tmpl.getComponent!CTargetParent().rel_pos = vec2(0,0);
|
||||||
|
|
@ -779,17 +780,17 @@ struct ShipWeaponSystem
|
||||||
weapon_tmpl.getComponent!CScale().value = vec2(4,16);
|
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!CWeapon() = CWeapon(0,CWeapon.Type.canon,1);
|
||||||
weapon_tmpl.getComponent!CDepth().depth = -1;
|
weapon_tmpl.getComponent!CDepth().value = -1;
|
||||||
weapon_tmpl.getComponent!CTexture().coords = vec4(136,96,4,16)*px;
|
weapon_tmpl.getComponent!CTexCoords().value = vec4(136,96,4,16)*px;
|
||||||
weapon_tmpl.getComponent!CWeaponLocation().rel_pos = vec2(0,12);
|
weapon_tmpl.getComponent!CWeaponLocation().rel_pos = vec2(0,12);
|
||||||
|
|
||||||
top_tmpl = launcher.manager.allocateTemplate(
|
top_tmpl = launcher.manager.allocateTemplate(
|
||||||
[CLocation.component_id, CTargetParent.component_id, CScale.component_id,
|
[CLocation.component_id, CTargetParent.component_id, CScale.component_id,
|
||||||
CTexture.component_id, CDepth.component_id].staticArray);
|
CTexCoords.component_id, CDepth.component_id].staticArray);
|
||||||
top_tmpl.getComponent!CTargetParent().rel_pos = vec2(0,1);
|
top_tmpl.getComponent!CTargetParent().rel_pos = vec2(0,1);
|
||||||
top_tmpl.getComponent!CScale().value = vec2(10,11);
|
top_tmpl.getComponent!CScale().value = vec2(10,11);
|
||||||
top_tmpl.getComponent!CDepth().depth = -2;
|
top_tmpl.getComponent!CDepth().value = -2;
|
||||||
top_tmpl.getComponent!CTexture().coords = vec4(112,96,10,11)*px;
|
top_tmpl.getComponent!CTexCoords().value = vec4(112,96,10,11)*px;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -829,21 +830,23 @@ struct ShipWeaponSystem
|
||||||
{
|
{
|
||||||
tower1_tmpl = launcher.manager.allocateTemplate(
|
tower1_tmpl = launcher.manager.allocateTemplate(
|
||||||
[CHitMark.component_id, CHitPoints.component_id, CLocation.component_id,
|
[CHitMark.component_id, CHitPoints.component_id, CLocation.component_id,
|
||||||
CTexture.component_id, CScale.component_id, CEnemy.component_id,
|
CTexCoords.component_id, CScale.component_id, CEnemy.component_id,
|
||||||
CShootGrid.component_id, CGuild.component_id, CInit.component_id,
|
CShootGrid.component_id, CGuild.component_id, CInit.component_id,
|
||||||
CChildren.component_id, CDepth.component_id, CTargetParent.component_id,
|
CChildren.component_id, CDepth.component_id, CTargetParent.component_id,
|
||||||
CSpawnUponDeath.component_id, CShootWaveUponDeath.component_id].staticArray
|
CSpawnUponDeath.component_id, CShootWaveUponDeath.component_id].staticArray
|
||||||
);
|
);
|
||||||
|
|
||||||
CTexture* tex_comp = tower1_tmpl.getComponent!CTexture;
|
/*CTexCoords* tex_comp = tower1_tmpl.getComponent!CTexCoords;
|
||||||
//tex_comp.tex = space_invaders.texture;//ship_tex;
|
//tex_comp.tex = space_invaders.texture;//ship_tex;
|
||||||
tex_comp.coords = vec4(96*px,96*px,16*px,16*px);
|
tex_comp.coords = vec4(96*px,96*px,16*px,16*px);
|
||||||
CLocation* loc_comp = tower1_tmpl.getComponent!CLocation;
|
CLocation* loc_comp = tower1_tmpl.getComponent!CLocation;
|
||||||
loc_comp.value = vec2(64,space_invaders.map_size.y - 16);
|
loc_comp.value = vec2(64,space_invaders.map_size.y - 16);*/
|
||||||
|
tower1_tmpl.getComponent!CTexCoords().value = vec4(96*px,96*px,16*px,16*px);
|
||||||
|
tower1_tmpl.getComponent!CLocation().value = vec2(64,space_invaders.map_size.y - 16);
|
||||||
tower1_tmpl.getComponent!CGuild().guild = 1;
|
tower1_tmpl.getComponent!CGuild().guild = 1;
|
||||||
tower1_tmpl.getComponent!CInit().type = CInit.Type.tower;
|
tower1_tmpl.getComponent!CInit().type = CInit.Type.tower;
|
||||||
tower1_tmpl.getComponent!CHitPoints().value = 10;
|
tower1_tmpl.getComponent!CHitPoints().value = 10;
|
||||||
tower1_tmpl.getComponent!CDepth().depth = -2;
|
tower1_tmpl.getComponent!CDepth().value = -2;
|
||||||
tower1_tmpl.getComponent!CShootWaveUponDeath().bullet_type = CWeapon.Type.canon;
|
tower1_tmpl.getComponent!CShootWaveUponDeath().bullet_type = CWeapon.Type.canon;
|
||||||
tower1_tmpl.getComponent!CTargetParent().rel_pos = vec2(-33,2);
|
tower1_tmpl.getComponent!CTargetParent().rel_pos = vec2(-33,2);
|
||||||
|
|
||||||
|
|
@ -851,11 +854,11 @@ struct ShipWeaponSystem
|
||||||
tower2_tmpl.getComponent!CTargetParent().rel_pos = vec2(33,2);
|
tower2_tmpl.getComponent!CTargetParent().rel_pos = vec2(33,2);
|
||||||
|
|
||||||
tower3_tmpl = launcher.manager.allocateTemplate(tower1_tmpl);
|
tower3_tmpl = launcher.manager.allocateTemplate(tower1_tmpl);
|
||||||
tower3_tmpl.getComponent!CDepth().depth = 0;
|
tower3_tmpl.getComponent!CDepth().value = 0;
|
||||||
tower3_tmpl.getComponent!CTargetParent().rel_pos = vec2(-40,-15);
|
tower3_tmpl.getComponent!CTargetParent().rel_pos = vec2(-40,-15);
|
||||||
|
|
||||||
tower4_tmpl = launcher.manager.allocateTemplate(tower1_tmpl);
|
tower4_tmpl = launcher.manager.allocateTemplate(tower1_tmpl);
|
||||||
tower4_tmpl.getComponent!CDepth().depth = 0;
|
tower4_tmpl.getComponent!CDepth().value = 0;
|
||||||
tower4_tmpl.getComponent!CTargetParent().rel_pos = vec2(40,-15);
|
tower4_tmpl.getComponent!CTargetParent().rel_pos = vec2(40,-15);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -966,7 +969,7 @@ struct DrawSystem
|
||||||
uint length;
|
uint length;
|
||||||
//uint thread_id;
|
//uint thread_id;
|
||||||
uint job_id;
|
uint job_id;
|
||||||
@readonly CTexture[] textures;
|
@readonly CTexCoords[] textures;
|
||||||
@readonly CLocation[] locations;
|
@readonly CLocation[] locations;
|
||||||
@readonly CScale[] scale;
|
@readonly CScale[] scale;
|
||||||
@readonly @optional CRotation[] rotation;
|
@readonly @optional CRotation[] rotation;
|
||||||
|
|
@ -992,7 +995,7 @@ struct DrawSystem
|
||||||
{
|
{
|
||||||
draw_data.color = 0x80808080 + 0x01010101 * data.hit_mark[i];
|
draw_data.color = 0x80808080 + 0x01010101 * data.hit_mark[i];
|
||||||
draw_data.depth = cast(short)(data.locations[i].y);
|
draw_data.depth = cast(short)(data.locations[i].y);
|
||||||
draw_data.coords = data.textures[i].coords;
|
draw_data.coords = data.textures[i].value;
|
||||||
draw_data.size = data.scale[i];
|
draw_data.size = data.scale[i];
|
||||||
draw_data.position = data.locations[i];
|
draw_data.position = data.locations[i];
|
||||||
launcher.renderer.draw(draw_data);
|
launcher.renderer.draw(draw_data);
|
||||||
|
|
@ -1005,7 +1008,7 @@ struct DrawSystem
|
||||||
{
|
{
|
||||||
draw_data.depth = cast(short)(data.locations[i].y);
|
draw_data.depth = cast(short)(data.locations[i].y);
|
||||||
draw_data.angle = data.rotation[i];
|
draw_data.angle = data.rotation[i];
|
||||||
draw_data.coords = data.textures[i].coords;
|
draw_data.coords = data.textures[i].value;
|
||||||
draw_data.size = data.scale[i];
|
draw_data.size = data.scale[i];
|
||||||
draw_data.position = data.locations[i];
|
draw_data.position = data.locations[i];
|
||||||
launcher.renderer.draw(draw_data);
|
launcher.renderer.draw(draw_data);
|
||||||
|
|
@ -1017,7 +1020,7 @@ struct DrawSystem
|
||||||
foreach(i; 0..data.length)
|
foreach(i; 0..data.length)
|
||||||
{
|
{
|
||||||
draw_data.depth = cast(short)(data.locations[i].y);
|
draw_data.depth = cast(short)(data.locations[i].y);
|
||||||
draw_data.coords = data.textures[i].coords;
|
draw_data.coords = data.textures[i].value;
|
||||||
draw_data.size = data.scale[i];
|
draw_data.size = data.scale[i];
|
||||||
draw_data.position = data.locations[i];
|
draw_data.position = data.locations[i];
|
||||||
launcher.renderer.draw(draw_data);
|
launcher.renderer.draw(draw_data);
|
||||||
|
|
@ -1036,7 +1039,7 @@ struct DrawSystem
|
||||||
draw_data.color = 0x80808080 + 0x01010101 * data.hit_mark[i];
|
draw_data.color = 0x80808080 + 0x01010101 * data.hit_mark[i];
|
||||||
draw_data.angle = data.rotation[i];
|
draw_data.angle = data.rotation[i];
|
||||||
draw_data.depth = cast(short)(data.depth[i] * 8 + data.locations[i].y);
|
draw_data.depth = cast(short)(data.depth[i] * 8 + data.locations[i].y);
|
||||||
draw_data.coords = data.textures[i].coords;
|
draw_data.coords = data.textures[i].value;
|
||||||
draw_data.size = data.scale[i];
|
draw_data.size = data.scale[i];
|
||||||
draw_data.position = data.locations[i];
|
draw_data.position = data.locations[i];
|
||||||
launcher.renderer.draw(draw_data);
|
launcher.renderer.draw(draw_data);
|
||||||
|
|
@ -1049,7 +1052,7 @@ struct DrawSystem
|
||||||
{
|
{
|
||||||
draw_data.color = 0x80808080 + 0x01010101 * data.hit_mark[i];
|
draw_data.color = 0x80808080 + 0x01010101 * data.hit_mark[i];
|
||||||
draw_data.depth = cast(short)(data.depth[i] * 8 + data.locations[i].y);
|
draw_data.depth = cast(short)(data.depth[i] * 8 + data.locations[i].y);
|
||||||
draw_data.coords = data.textures[i].coords;
|
draw_data.coords = data.textures[i].value;
|
||||||
draw_data.size = data.scale[i];
|
draw_data.size = data.scale[i];
|
||||||
draw_data.position = data.locations[i];
|
draw_data.position = data.locations[i];
|
||||||
launcher.renderer.draw(draw_data);
|
launcher.renderer.draw(draw_data);
|
||||||
|
|
@ -1063,7 +1066,7 @@ struct DrawSystem
|
||||||
{
|
{
|
||||||
draw_data.angle = data.rotation[i];
|
draw_data.angle = data.rotation[i];
|
||||||
draw_data.depth = cast(short)(data.depth[i] * 8 + data.locations[i].y);
|
draw_data.depth = cast(short)(data.depth[i] * 8 + data.locations[i].y);
|
||||||
draw_data.coords = data.textures[i].coords;
|
draw_data.coords = data.textures[i].value;
|
||||||
draw_data.size = data.scale[i];
|
draw_data.size = data.scale[i];
|
||||||
draw_data.position = data.locations[i];
|
draw_data.position = data.locations[i];
|
||||||
launcher.renderer.draw(draw_data);
|
launcher.renderer.draw(draw_data);
|
||||||
|
|
@ -1075,7 +1078,7 @@ struct DrawSystem
|
||||||
foreach(i; 0..data.length)
|
foreach(i; 0..data.length)
|
||||||
{
|
{
|
||||||
draw_data.depth = cast(short)(data.depth[i] * 8 + data.locations[i].y);
|
draw_data.depth = cast(short)(data.depth[i] * 8 + data.locations[i].y);
|
||||||
draw_data.coords = data.textures[i].coords;
|
draw_data.coords = data.textures[i].value;
|
||||||
draw_data.size = data.scale[i];
|
draw_data.size = data.scale[i];
|
||||||
draw_data.position = data.locations[i];
|
draw_data.position = data.locations[i];
|
||||||
launcher.renderer.draw(draw_data);
|
launcher.renderer.draw(draw_data);
|
||||||
|
|
@ -1138,31 +1141,31 @@ struct ShootingSystem
|
||||||
void onCreate()
|
void onCreate()
|
||||||
{
|
{
|
||||||
/*bullet_tmpl[0] = launcher.manager.allocateTemplate(
|
/*bullet_tmpl[0] = launcher.manager.allocateTemplate(
|
||||||
[CLocation.component_id, CTexture.component_id, CVelocity.component_id,
|
[CLocation.component_id, CTexCoords.component_id, CVelocity.component_id,
|
||||||
CScale.component_id, CBullet.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!CTexCoords().value = vec4(0,24,2,8)*px;
|
||||||
bullet_tmpl[0].getComponent!CScale().value = vec2(2,8);
|
bullet_tmpl[0].getComponent!CScale().value = vec2(2,8);
|
||||||
|
|
||||||
bullet_tmpl[1] = launcher.manager.allocateTemplate(bullet_tmpl[0]);
|
bullet_tmpl[1] = launcher.manager.allocateTemplate(bullet_tmpl[0]);
|
||||||
bullet_tmpl[2] = 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!CTexCoords().value = vec4(64,32,8,16)*px;
|
||||||
bullet_tmpl[2].getComponent!CScale().value = vec2(8,16);
|
bullet_tmpl[2].getComponent!CScale().value = vec2(8,16);
|
||||||
bullet_tmpl[3] = launcher.manager.allocateTemplate(bullet_tmpl[0]);
|
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!CTexCoords().value = vec4(56,32,2,2)*px;
|
||||||
bullet_tmpl[3].getComponent!CScale().value = vec2(2,2);
|
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!CTexCoords().value = vec4(48,32,8,8)*px;
|
||||||
// bullet_tmpl[3].getComponent!CScale().value = vec2(8,8);
|
// bullet_tmpl[3].getComponent!CScale().value = vec2(8,8);
|
||||||
bullet_tmpl[4] = launcher.manager.allocateTemplate(bullet_tmpl[0]);*/
|
bullet_tmpl[4] = launcher.manager.allocateTemplate(bullet_tmpl[0]);*/
|
||||||
|
|
||||||
|
|
||||||
fire_tmpl = launcher.manager.allocateTemplate(
|
fire_tmpl = launcher.manager.allocateTemplate(
|
||||||
[CLocation.component_id, CTexture.component_id, CScale.component_id,
|
[CLocation.component_id, CTexCoords.component_id, CScale.component_id,
|
||||||
CAnimation.component_id, CParticle.component_id, CRotation.component_id,
|
CAnimation.component_id, CParticle.component_id, CRotation.component_id,
|
||||||
CVelocity.component_id, CDamping.component_id].staticArray
|
CVelocity.component_id, CDamping.component_id].staticArray
|
||||||
);
|
);
|
||||||
|
|
||||||
fire_tmpl.getComponent!CTexture().coords = vec4(96,64,8,16)*px;
|
fire_tmpl.getComponent!CTexCoords().value = vec4(96,64,8,16)*px;
|
||||||
fire_tmpl.getComponent!CScale().value = vec2(8,16);
|
fire_tmpl.getComponent!CScale().value = vec2(8,16);
|
||||||
fire_tmpl.getComponent!(CParticle).life = 300;
|
fire_tmpl.getComponent!(CParticle).life = 300;
|
||||||
*fire_tmpl.getComponent!(CAnimation) = CAnimation(fire_frames, 0, 3);
|
*fire_tmpl.getComponent!(CAnimation) = CAnimation(fire_frames, 0, 3);
|
||||||
|
|
@ -1364,7 +1367,7 @@ struct ParticleEmittingSystem
|
||||||
void onCreate()
|
void onCreate()
|
||||||
{
|
{
|
||||||
templates[0] = launcher.manager.allocateTemplate(
|
templates[0] = launcher.manager.allocateTemplate(
|
||||||
[CLocation.component_id, CTexture.component_id, CScale.component_id,
|
[CLocation.component_id, CTexCoords.component_id, CScale.component_id,
|
||||||
CAnimation.component_id, CParticle.component_id, CRotation.component_id,
|
CAnimation.component_id, CParticle.component_id, CRotation.component_id,
|
||||||
CVelocity.component_id, CDamping.component_id, CDepth.component_id].staticArray);
|
CVelocity.component_id, CDamping.component_id, CDepth.component_id].staticArray);
|
||||||
*templates[0].getComponent!CAnimation() = CAnimation(flashes,0,2);
|
*templates[0].getComponent!CAnimation() = CAnimation(flashes,0,2);
|
||||||
|
|
@ -1400,7 +1403,7 @@ struct ParticleEmittingSystem
|
||||||
|
|
||||||
if(data.depth)
|
if(data.depth)
|
||||||
{
|
{
|
||||||
depth.depth = data.depth[i];
|
depth.value = data.depth[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
launcher.manager.addEntity(templates[0],[data.location[i].ref_,velocity.ref_,depth.ref_].staticArray);
|
launcher.manager.addEntity(templates[0],[data.location[i].ref_,velocity.ref_,depth.ref_].staticArray);
|
||||||
|
|
@ -1659,18 +1662,18 @@ struct HitPointsSystem
|
||||||
void onCreate()
|
void onCreate()
|
||||||
{
|
{
|
||||||
upgrade_tmpl = launcher.manager.allocateTemplate(
|
upgrade_tmpl = launcher.manager.allocateTemplate(
|
||||||
[CVelocity.component_id, CLocation.component_id, CTexture.component_id,
|
[CVelocity.component_id, CLocation.component_id, CTexCoords.component_id,
|
||||||
CScale.component_id, CUpgrade.component_id, CAnimation.component_id,
|
CScale.component_id, CUpgrade.component_id, CAnimation.component_id,
|
||||||
CAnimationLooped.component_id].staticArray);
|
CAnimationLooped.component_id].staticArray);
|
||||||
//tex_comp.tex = space_invaders.texture;//ship_tex;
|
//tex_comp.tex = space_invaders.texture;//ship_tex;
|
||||||
upgrade_tmpl.getComponent!CTexture().coords = vec4(0*px,32*px,16*px,16*px);
|
upgrade_tmpl.getComponent!CTexCoords().value = vec4(0*px,32*px,16*px,16*px);
|
||||||
*upgrade_tmpl.getComponent!CAnimation = CAnimation(upgrade_laser_frames, 0, 1);
|
*upgrade_tmpl.getComponent!CAnimation = CAnimation(upgrade_laser_frames, 0, 1);
|
||||||
upgrade_tmpl.getComponent!CVelocity().value = vec2(0,-0.1);
|
upgrade_tmpl.getComponent!CVelocity().value = vec2(0,-0.1);
|
||||||
|
|
||||||
explosion_tmpl = launcher.manager.allocateTemplate(
|
explosion_tmpl = launcher.manager.allocateTemplate(
|
||||||
[CDepth.component_id, CParticle.component_id, CLocation.component_id,
|
[CDepth.component_id, CParticle.component_id, CLocation.component_id,
|
||||||
CTexture.component_id, CScale.component_id, CAnimation.component_id].staticArray);
|
CTexCoords.component_id, CScale.component_id, CAnimation.component_id].staticArray);
|
||||||
//explosion_tmpl.getComponent!(CTexture).tex = space_invaders.texture;
|
//explosion_tmpl.getComponent!(CTexCoords).tex = space_invaders.texture;
|
||||||
*explosion_tmpl.getComponent!CAnimation = CAnimation(explosion_laser_frames, 0, 1.333);
|
*explosion_tmpl.getComponent!CAnimation = CAnimation(explosion_laser_frames, 0, 1.333);
|
||||||
explosion_tmpl.getComponent!(CParticle).life = 600;
|
explosion_tmpl.getComponent!(CParticle).life = 600;
|
||||||
*explosion_tmpl.getComponent!CDepth = -1;
|
*explosion_tmpl.getComponent!CDepth = -1;
|
||||||
|
|
@ -2005,7 +2008,8 @@ struct AnimationSystem
|
||||||
{
|
{
|
||||||
uint length;
|
uint length;
|
||||||
CAnimation[] animation;
|
CAnimation[] animation;
|
||||||
CTexture[] texture;
|
//CTexture[] texture;
|
||||||
|
CTexCoords[] texcoords;
|
||||||
@optional @readonly CAnimationLooped[] looped;
|
@optional @readonly CAnimationLooped[] looped;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2020,7 +2024,7 @@ struct AnimationSystem
|
||||||
while(cast(uint)data.animation[i].time >= data.animation[i].frames.length)data.animation[i].time -= cast(float)data.animation[i].frames.length;
|
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);
|
if(cast(uint)(data.animation[i].time) >= data.animation[i].frames.length)assert(0);
|
||||||
uint index = cast(uint)(data.animation[i].time);
|
uint index = cast(uint)(data.animation[i].time);
|
||||||
if(index < data.animation[i].frames.length)data.texture[i].coords = data.animation[i].frames[index];
|
if(index < data.animation[i].frames.length)data.texcoords[i].value = data.animation[i].frames[index];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -2030,7 +2034,7 @@ struct AnimationSystem
|
||||||
data.animation[i].time += dt * data.animation[i].speed;
|
data.animation[i].time += dt * data.animation[i].speed;
|
||||||
if(cast(uint)data.animation[i].time >= data.animation[i].frames.length)data.animation[i].time = data.animation[i].frames.length - 0.9;
|
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);
|
uint index = cast(uint)(data.animation[i].time);
|
||||||
if(index < data.animation[i].frames.length)data.texture[i].coords = data.animation[i].frames[index];
|
if(index < data.animation[i].frames.length)data.texcoords[i].value = data.animation[i].frames[index];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2241,7 +2245,7 @@ struct InputMovementSystem
|
||||||
//components are treated as required by default
|
//components are treated as required by default
|
||||||
//CLocation[] locations;
|
//CLocation[] locations;
|
||||||
CVelocity[] velocity;
|
CVelocity[] velocity;
|
||||||
CTexture[] textures;
|
//CTexture[] textures;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -2336,7 +2340,8 @@ void spaceInvadersStart()
|
||||||
launcher.manager.registerDependency(ShootGridDependency);
|
launcher.manager.registerDependency(ShootGridDependency);
|
||||||
|
|
||||||
launcher.manager.registerComponent!CLocation;
|
launcher.manager.registerComponent!CLocation;
|
||||||
launcher.manager.registerComponent!CTexture;
|
launcher.manager.registerComponent!CTexCoords;
|
||||||
|
//launcher.manager.registerComponent!CTexture;
|
||||||
launcher.manager.registerComponent!CInput;
|
launcher.manager.registerComponent!CInput;
|
||||||
launcher.manager.registerComponent!CShip;
|
launcher.manager.registerComponent!CShip;
|
||||||
launcher.manager.registerComponent!CEnemy;
|
launcher.manager.registerComponent!CEnemy;
|
||||||
|
|
@ -2478,12 +2483,12 @@ void spaceInvadersStart()
|
||||||
{
|
{
|
||||||
space_invaders.ship_tmpl = launcher.manager.allocateTemplate(
|
space_invaders.ship_tmpl = launcher.manager.allocateTemplate(
|
||||||
[CVelocity.component_id, CHitMark.component_id, CHitPoints.component_id,
|
[CVelocity.component_id, CHitMark.component_id, CHitPoints.component_id,
|
||||||
CLocation.component_id, CTexture.component_id, CInput.component_id,
|
CLocation.component_id, CTexCoords.component_id, CInput.component_id,
|
||||||
CShip.component_id, CScale.component_id, CColliderScale.component_id,
|
CShip.component_id, CScale.component_id, CColliderScale.component_id,
|
||||||
CShootDirection.component_id, CShootGrid.component_id, CGuild.component_id,
|
CShootDirection.component_id, CShootGrid.component_id, CGuild.component_id,
|
||||||
CDamping.component_id, CChildren.component_id, CInit.component_id].staticArray
|
CDamping.component_id, CChildren.component_id, CInit.component_id].staticArray
|
||||||
);
|
);
|
||||||
space_invaders.ship_tmpl.getComponent!CTexture().coords = vec4(0,80,48,32)*px;
|
space_invaders.ship_tmpl.getComponent!CTexCoords().value = vec4(0,80,48,32)*px;
|
||||||
space_invaders.ship_tmpl.getComponent!CScale().value = vec2(48,32);
|
space_invaders.ship_tmpl.getComponent!CScale().value = vec2(48,32);
|
||||||
space_invaders.ship_tmpl.getComponent!CHitPoints().value = 1000;
|
space_invaders.ship_tmpl.getComponent!CHitPoints().value = 1000;
|
||||||
space_invaders.ship_tmpl.getComponent!CDamping().value = 7;
|
space_invaders.ship_tmpl.getComponent!CDamping().value = 7;
|
||||||
|
|
@ -2494,10 +2499,10 @@ void spaceInvadersStart()
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
ushort[6] components = [CLocation.component_id, CTexture.component_id, CVelocity.component_id, CScale.component_id, CBullet.component_id, CGuild.component_id];
|
ushort[6] components = [CLocation.component_id, CTexCoords.component_id, CVelocity.component_id, CScale.component_id, CBullet.component_id, CGuild.component_id];
|
||||||
space_invaders.laser_tmpl = launcher.manager.allocateTemplate(components);
|
space_invaders.laser_tmpl = launcher.manager.allocateTemplate(components);
|
||||||
|
|
||||||
space_invaders.laser_tmpl.getComponent!CTexture().coords = vec4(0,24,2,8)*px;
|
space_invaders.laser_tmpl.getComponent!CTexCoords().value = vec4(0,24,2,8)*px;
|
||||||
space_invaders.laser_tmpl.getComponent!CScale().value = vec2(2,8);
|
space_invaders.laser_tmpl.getComponent!CScale().value = vec2(2,8);
|
||||||
space_invaders.laser_tmpl.getComponent!CVelocity().value = vec2(0,1);
|
space_invaders.laser_tmpl.getComponent!CVelocity().value = vec2(0,1);
|
||||||
}
|
}
|
||||||
|
|
@ -2513,7 +2518,7 @@ void spaceInvadersStart()
|
||||||
{
|
{
|
||||||
boss_tmpl = launcher.manager.allocateTemplate(
|
boss_tmpl = launcher.manager.allocateTemplate(
|
||||||
[CHitMark.component_id, CParts.component_id, CLocation.component_id,
|
[CHitMark.component_id, CParts.component_id, CLocation.component_id,
|
||||||
CTexture.component_id, CScale.component_id, CEnemy.component_id,
|
CTexCoords.component_id, CScale.component_id, CEnemy.component_id,
|
||||||
CBoss.component_id, CGuild.component_id, CInit.component_id,
|
CBoss.component_id, CGuild.component_id, CInit.component_id,
|
||||||
CChildren.component_id, CSideMove.component_id, CVelocity.component_id,
|
CChildren.component_id, CSideMove.component_id, CVelocity.component_id,
|
||||||
CDepth.component_id].staticArray
|
CDepth.component_id].staticArray
|
||||||
|
|
@ -2524,11 +2529,11 @@ void spaceInvadersStart()
|
||||||
//tex_comp.coords = vec4(128*px,0*px,96*px,48*px);
|
//tex_comp.coords = vec4(128*px,0*px,96*px,48*px);
|
||||||
//CLocation* loc_comp = boss_tmpl.getComponent!CLocation;
|
//CLocation* loc_comp = boss_tmpl.getComponent!CLocation;
|
||||||
//loc_comp.value = vec2(64,space_invaders.map_size.y - 16);
|
//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!CTexCoords().value = vec4(128,0,96,48)*px;
|
||||||
boss_tmpl.getComponent!CGuild().guild = 1;
|
boss_tmpl.getComponent!CGuild().guild = 1;
|
||||||
boss_tmpl.getComponent!CInit().type = CInit.Type.boss;
|
boss_tmpl.getComponent!CInit().type = CInit.Type.boss;
|
||||||
boss_tmpl.getComponent!CScale().value = vec2(96,48);
|
boss_tmpl.getComponent!CScale().value = vec2(96,48);
|
||||||
boss_tmpl.getComponent!CDepth().depth = -1;
|
boss_tmpl.getComponent!CDepth().value = -1;
|
||||||
boss_tmpl.getComponent!CParts().count = 4;
|
boss_tmpl.getComponent!CParts().count = 4;
|
||||||
boss_tmpl.getComponent!CVelocity().value = vec2(0.05,0);
|
boss_tmpl.getComponent!CVelocity().value = vec2(0.05,0);
|
||||||
}
|
}
|
||||||
|
|
@ -2536,12 +2541,12 @@ void spaceInvadersStart()
|
||||||
{
|
{
|
||||||
tower_tmpl = launcher.manager.allocateTemplate(
|
tower_tmpl = launcher.manager.allocateTemplate(
|
||||||
[CHitMark.component_id, CHitPoints.component_id, CLocation.component_id,
|
[CHitMark.component_id, CHitPoints.component_id, CLocation.component_id,
|
||||||
CTexture.component_id, CScale.component_id, CEnemy.component_id,
|
CTexCoords.component_id, CScale.component_id, CEnemy.component_id,
|
||||||
CShootGrid.component_id, CGuild.component_id, CInit.component_id,
|
CShootGrid.component_id, CGuild.component_id, CInit.component_id,
|
||||||
CChildren.component_id].staticArray
|
CChildren.component_id].staticArray
|
||||||
);
|
);
|
||||||
|
|
||||||
tower_tmpl.getComponent!CTexture().coords = vec4(96,96,16,16)*px;
|
tower_tmpl.getComponent!CTexCoords().value = vec4(96,96,16,16)*px;
|
||||||
tower_tmpl.getComponent!CGuild().guild = 1;
|
tower_tmpl.getComponent!CGuild().guild = 1;
|
||||||
tower_tmpl.getComponent!CInit().type = CInit.Type.tower;
|
tower_tmpl.getComponent!CInit().type = CInit.Type.tower;
|
||||||
tower_tmpl.getComponent!CHitPoints().value = 10;
|
tower_tmpl.getComponent!CHitPoints().value = 10;
|
||||||
|
|
@ -2551,12 +2556,12 @@ void spaceInvadersStart()
|
||||||
space_invaders.enemy_tmpl = launcher.manager.allocateTemplate(
|
space_invaders.enemy_tmpl = launcher.manager.allocateTemplate(
|
||||||
[CWeaponLocation.component_id, CHitMark.component_id, CHitPoints.component_id,
|
[CWeaponLocation.component_id, CHitMark.component_id, CHitPoints.component_id,
|
||||||
CVelocity.component_id, CAutoShoot.component_id, CLocation.component_id,
|
CVelocity.component_id, CAutoShoot.component_id, CLocation.component_id,
|
||||||
CTexture.component_id, CScale.component_id, CWeapon.component_id,
|
CTexCoords.component_id, CScale.component_id, CWeapon.component_id,
|
||||||
CEnemy.component_id, CShootDirection.component_id, CShootGrid.component_id,
|
CEnemy.component_id, CShootDirection.component_id, CShootGrid.component_id,
|
||||||
CGuild.component_id].staticArray
|
CGuild.component_id].staticArray
|
||||||
);
|
);
|
||||||
|
|
||||||
space_invaders.enemy_tmpl.getComponent!CTexture().coords = vec4(32,32,16,16)*px;
|
space_invaders.enemy_tmpl.getComponent!CTexCoords().value = vec4(32,32,16,16)*px;
|
||||||
space_invaders.enemy_tmpl.getComponent!CShootDirection().direction = Direction.down;
|
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!CVelocity().value = vec2(0.1,0);
|
||||||
space_invaders.enemy_tmpl.getComponent!CGuild().guild = 1;
|
space_invaders.enemy_tmpl.getComponent!CGuild().guild = 1;
|
||||||
|
|
@ -2588,8 +2593,8 @@ void spaceInvadersStart()
|
||||||
EntityTemplate* upgrade_tmpl;
|
EntityTemplate* upgrade_tmpl;
|
||||||
|
|
||||||
{
|
{
|
||||||
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);
|
upgrade_tmpl = launcher.manager.allocateTemplate([CVelocity.component_id, CLocation.component_id, CTexCoords.component_id, CScale.component_id, CUpgrade.component_id, CAnimationLooped.component_id, CAnimation.component_id].staticArray);
|
||||||
upgrade_tmpl.getComponent!CTexture().coords = vec4(0,32,16,16)*px;
|
upgrade_tmpl.getComponent!CTexCoords().value = vec4(0,32,16,16)*px;
|
||||||
upgrade_tmpl.getComponent!CVelocity().value = vec2(0,-0.1);
|
upgrade_tmpl.getComponent!CVelocity().value = vec2(0,-0.1);
|
||||||
*upgrade_tmpl.getComponent!CAnimation = CAnimation(HitPointsSystem.upgrade_laser_frames, 0, 0.75);
|
*upgrade_tmpl.getComponent!CAnimation = CAnimation(HitPointsSystem.upgrade_laser_frames, 0, 0.75);
|
||||||
}
|
}
|
||||||
|
|
@ -2600,20 +2605,20 @@ void spaceInvadersStart()
|
||||||
grouped_tmpl = launcher.manager.allocateTemplate(grouped_id);
|
grouped_tmpl = launcher.manager.allocateTemplate(grouped_id);
|
||||||
|
|
||||||
space_invaders.bullet_tmpl[0] = launcher.manager.allocateTemplate(
|
space_invaders.bullet_tmpl[0] = launcher.manager.allocateTemplate(
|
||||||
[CLocation.component_id, CTexture.component_id, CVelocity.component_id,
|
[CLocation.component_id, CTexCoords.component_id, CVelocity.component_id,
|
||||||
CScale.component_id, CBullet.component_id, CGuild.component_id].staticArray
|
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!CTexCoords().value = vec4(0,24,2,8)*px;
|
||||||
space_invaders.bullet_tmpl[0].getComponent!CScale().value = vec2(2,8);
|
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[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] = 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!CTexCoords().value = vec4(64,32,8,16)*px;
|
||||||
space_invaders.bullet_tmpl[2].getComponent!CScale().value = vec2(8,16);
|
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] = 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!CTexCoords().value = vec4(56,32,2,2)*px;
|
||||||
space_invaders.bullet_tmpl[3].getComponent!CScale().value = vec2(2,2);
|
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!CTexCoords().value = vec4(48,32,8,8)*px;
|
||||||
// bullet_tmpl[3].getComponent!CScale().value = vec2(8,8);
|
// bullet_tmpl[3].getComponent!CScale().value = vec2(8,8);
|
||||||
space_invaders.bullet_tmpl[4] = launcher.manager.allocateTemplate(space_invaders.bullet_tmpl[0]);
|
space_invaders.bullet_tmpl[4] = launcher.manager.allocateTemplate(space_invaders.bullet_tmpl[0]);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,8 @@ import bubel.ecs.core;
|
||||||
|
|
||||||
import ecs_utils.math.vector;
|
import ecs_utils.math.vector;
|
||||||
|
|
||||||
|
import gui.attributes;
|
||||||
|
|
||||||
struct CLocation
|
struct CLocation
|
||||||
{
|
{
|
||||||
mixin ECS.Component;
|
mixin ECS.Component;
|
||||||
|
|
@ -11,4 +13,47 @@ struct CLocation
|
||||||
alias value this;
|
alias value this;
|
||||||
|
|
||||||
vec2 value = vec2(0);
|
vec2 value = vec2(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct CScale
|
||||||
|
{
|
||||||
|
mixin ECS.Component;
|
||||||
|
|
||||||
|
alias value this;///use component as it value
|
||||||
|
|
||||||
|
vec2 value = vec2(16,16);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct CRotation
|
||||||
|
{
|
||||||
|
mixin ECS.Component;
|
||||||
|
|
||||||
|
alias value this;///use component as it value
|
||||||
|
|
||||||
|
float value = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct CDepth
|
||||||
|
{
|
||||||
|
mixin ECS.Component;
|
||||||
|
|
||||||
|
alias value this;
|
||||||
|
|
||||||
|
short value;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct CColor
|
||||||
|
{
|
||||||
|
mixin ECS.Component;
|
||||||
|
|
||||||
|
alias value this;
|
||||||
|
|
||||||
|
@GUIColor uint value;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct CSelected
|
||||||
|
{
|
||||||
|
mixin ECS.Component;
|
||||||
|
|
||||||
|
bool value = false;
|
||||||
}
|
}
|
||||||
178
demos/source/game_core/rendering.d
Normal file
178
demos/source/game_core/rendering.d
Normal file
|
|
@ -0,0 +1,178 @@
|
||||||
|
module game_core.rendering;
|
||||||
|
|
||||||
|
import bubel.ecs.core;
|
||||||
|
import bubel.ecs.attributes;
|
||||||
|
|
||||||
|
import ecs_utils.math.vector;
|
||||||
|
import ecs_utils.gfx.texture;
|
||||||
|
|
||||||
|
import game_core.basic;
|
||||||
|
|
||||||
|
struct CTexCoords
|
||||||
|
{
|
||||||
|
mixin ECS.Component;
|
||||||
|
|
||||||
|
alias value this;///use component as it value
|
||||||
|
|
||||||
|
vec4 value;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct CTexCoordsIndex
|
||||||
|
{
|
||||||
|
mixin ECS.Component;
|
||||||
|
|
||||||
|
ushort value;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct TexCoordsManager
|
||||||
|
{
|
||||||
|
import bubel.ecs.vector;
|
||||||
|
import bubel.ecs.hash_map;
|
||||||
|
|
||||||
|
Vector!vec4 coords;
|
||||||
|
HashMap!(vec4,ushort) coords_map;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct DrawSystem
|
||||||
|
{
|
||||||
|
mixin ECS.System!32;
|
||||||
|
|
||||||
|
import ecs_utils.gfx.renderer : Renderer;
|
||||||
|
|
||||||
|
struct EntitiesData
|
||||||
|
{
|
||||||
|
uint length;
|
||||||
|
//uint thread_id;
|
||||||
|
uint job_id;
|
||||||
|
@readonly CLocation[] locations;
|
||||||
|
@readonly 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
Renderer.DrawData default_data;
|
||||||
|
|
||||||
|
void onUpdate(EntitiesData data)
|
||||||
|
{
|
||||||
|
import app : launcher;
|
||||||
|
|
||||||
|
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(!data.color)
|
||||||
|
{
|
||||||
|
if(!data.rotation)
|
||||||
|
{
|
||||||
|
foreach(i; 0..data.length)
|
||||||
|
{
|
||||||
|
draw_data.coords = data.texcoord[i];
|
||||||
|
draw_data.size = data.scale[i];
|
||||||
|
draw_data.position = data.locations[i];
|
||||||
|
launcher.renderer.draw(draw_data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
foreach(i; 0..data.length)
|
||||||
|
{
|
||||||
|
draw_data.angle = data.rotation[i];
|
||||||
|
draw_data.coords = data.texcoord[i];
|
||||||
|
draw_data.size = data.scale[i];
|
||||||
|
draw_data.position = data.locations[i];
|
||||||
|
launcher.renderer.draw(draw_data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(!data.rotation)
|
||||||
|
{
|
||||||
|
foreach(i; 0..data.length)
|
||||||
|
{
|
||||||
|
draw_data.color = data.color[i];
|
||||||
|
draw_data.coords = data.texcoord[i];
|
||||||
|
draw_data.size = data.scale[i];
|
||||||
|
draw_data.position = data.locations[i];
|
||||||
|
launcher.renderer.draw(draw_data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
foreach(i; 0..data.length)
|
||||||
|
{
|
||||||
|
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];
|
||||||
|
launcher.renderer.draw(draw_data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(!data.color)
|
||||||
|
{
|
||||||
|
if(!data.rotation)
|
||||||
|
{
|
||||||
|
foreach(i; 0..data.length)
|
||||||
|
{
|
||||||
|
draw_data.depth = data.depth[i];
|
||||||
|
draw_data.coords = data.texcoord[i];
|
||||||
|
draw_data.size = data.scale[i];
|
||||||
|
draw_data.position = data.locations[i];
|
||||||
|
launcher.renderer.draw(draw_data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
foreach(i; 0..data.length)
|
||||||
|
{
|
||||||
|
draw_data.depth = data.depth[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];
|
||||||
|
launcher.renderer.draw(draw_data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
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];
|
||||||
|
launcher.renderer.draw(draw_data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
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];
|
||||||
|
draw_data.position = data.locations[i];
|
||||||
|
launcher.renderer.draw(draw_data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -173,9 +173,21 @@ struct GUIManager
|
||||||
{
|
{
|
||||||
switch(member_type.sizeof)
|
switch(member_type.sizeof)
|
||||||
{
|
{
|
||||||
case 1: comp_edit.variables[comp_edit.used++] = VariableGUI(VariableGUI.Type.byte_,member_str,offset);break;
|
case 1:
|
||||||
case 2: comp_edit.variables[comp_edit.used++] = VariableGUI(VariableGUI.Type.short_,member_str,offset);break;
|
comp_edit.variables[comp_edit.used++] = VariableGUI(VariableGUI.Type.byte_,member_str,offset);
|
||||||
case 4: comp_edit.variables[comp_edit.used++] = VariableGUI(VariableGUI.Type.int_,member_str,offset);break;
|
comp_edit.variables[comp_edit.used-1].int_.min = byte.min;
|
||||||
|
comp_edit.variables[comp_edit.used-1].int_.max = byte.max;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
comp_edit.variables[comp_edit.used++] = VariableGUI(VariableGUI.Type.short_,member_str,offset);
|
||||||
|
comp_edit.variables[comp_edit.used-1].int_.min = short.min;
|
||||||
|
comp_edit.variables[comp_edit.used-1].int_.max = short.max;
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
comp_edit.variables[comp_edit.used++] = VariableGUI(VariableGUI.Type.int_,member_str,offset);
|
||||||
|
comp_edit.variables[comp_edit.used-1].int_.min = int.min;
|
||||||
|
comp_edit.variables[comp_edit.used-1].int_.max = int.max;
|
||||||
|
break;
|
||||||
default:break;
|
default:break;
|
||||||
}
|
}
|
||||||
static if(hasUDA!(member,GUIRange))
|
static if(hasUDA!(member,GUIRange))
|
||||||
|
|
@ -183,10 +195,10 @@ struct GUIManager
|
||||||
comp_edit.variables[comp_edit.used-1].int_.min = getUDAs!(member,GUIRange)[0].min;
|
comp_edit.variables[comp_edit.used-1].int_.min = getUDAs!(member,GUIRange)[0].min;
|
||||||
comp_edit.variables[comp_edit.used-1].int_.max = getUDAs!(member,GUIRange)[1].max;
|
comp_edit.variables[comp_edit.used-1].int_.max = getUDAs!(member,GUIRange)[1].max;
|
||||||
}
|
}
|
||||||
{
|
/*{
|
||||||
comp_edit.variables[comp_edit.used-1].int_.min = int.min;
|
comp_edit.variables[comp_edit.used-1].int_.min = int.min;
|
||||||
comp_edit.variables[comp_edit.used-1].int_.max = int.max;
|
comp_edit.variables[comp_edit.used-1].int_.max = int.max;
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else static if(__traits(isScalar,member_type))
|
else static if(__traits(isScalar,member_type))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue