-removed launcher.manager (gEntityManager used instead)
-removed somee comments, unneded code -added some comments/documentation
This commit is contained in:
parent
3b954b732b
commit
27154c809e
10 changed files with 583 additions and 688 deletions
|
|
@ -58,7 +58,6 @@ struct Launcher
|
||||||
ImGuiContext* context;
|
ImGuiContext* context;
|
||||||
SDL_Window* window;
|
SDL_Window* window;
|
||||||
SDL_GLContext gl_context;
|
SDL_GLContext gl_context;
|
||||||
EntityManager* manager;
|
|
||||||
/*bool function() loop;
|
/*bool function() loop;
|
||||||
void function() end;
|
void function() end;
|
||||||
void function(SDL_Event*) event;*/
|
void function(SDL_Event*) event;*/
|
||||||
|
|
@ -126,19 +125,19 @@ struct Launcher
|
||||||
gui_manager.clear();
|
gui_manager.clear();
|
||||||
//launcher.ent
|
//launcher.ent
|
||||||
|
|
||||||
manager.begin();
|
gEntityManager.begin();
|
||||||
manager.update("clean");
|
gEntityManager.update("clean");
|
||||||
manager.end();
|
gEntityManager.end();
|
||||||
|
|
||||||
if(this.demo.deinitialize)this.demo.deinitialize();
|
if(this.demo.deinitialize)this.demo.deinitialize();
|
||||||
|
|
||||||
foreach(ref system; manager.systems)
|
foreach(ref system; gEntityManager.systems)
|
||||||
{
|
{
|
||||||
if(system.id != becsID!CountSystem && system.id != becsID!CleanSystem)system.disable();
|
if(system.id != becsID!CountSystem && system.id != becsID!CleanSystem)system.disable();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*launcher.manager.getSystem(becsID!CountSystem).enable();
|
/*gEntityManager.getSystem(becsID!CountSystem).enable();
|
||||||
launcher.manager.getSystem(becsID!CleanSystem).enable();//*/
|
gEntityManager.getSystem(becsID!CleanSystem).enable();//*/
|
||||||
|
|
||||||
if(callbacks.register)callbacks.register();
|
if(callbacks.register)callbacks.register();
|
||||||
if(callbacks.initialize)callbacks.initialize();
|
if(callbacks.initialize)callbacks.initialize();
|
||||||
|
|
@ -271,11 +270,11 @@ struct Launcher
|
||||||
//else if(position.y > 299)position.y = 299;
|
//else if(position.y > 299)position.y = 299;
|
||||||
*location = position;
|
*location = position;
|
||||||
}
|
}
|
||||||
manager.addEntity(tmpl);
|
gEntityManager.addEntity(tmpl);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
manager.callEntitiesFunction!IteratorSystem(&iterator.removeEntity);
|
gEntityManager.callEntitiesFunction!IteratorSystem(&iterator.removeEntity);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Tool.component_manipulator:
|
case Tool.component_manipulator:
|
||||||
|
|
@ -289,21 +288,21 @@ struct Launcher
|
||||||
{
|
{
|
||||||
ushort[1] rcomps = [gui_manager.getSelectedComponent().component_id];
|
ushort[1] rcomps = [gui_manager.getSelectedComponent().component_id];
|
||||||
iterator.rem_comps = rcomps;
|
iterator.rem_comps = rcomps;
|
||||||
manager.callEntitiesFunction!IteratorSystem(&iterator.overrideComponent);
|
gEntityManager.callEntitiesFunction!IteratorSystem(&iterator.overrideComponent);
|
||||||
}
|
}
|
||||||
else manager.callEntitiesFunction!IteratorSystem(&iterator.addComponent);
|
else gEntityManager.callEntitiesFunction!IteratorSystem(&iterator.addComponent);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ushort[1] comps = [gui_manager.getSelectedComponent().component_id];
|
ushort[1] comps = [gui_manager.getSelectedComponent().component_id];
|
||||||
iterator.rem_comps = comps;
|
iterator.rem_comps = comps;
|
||||||
manager.callEntitiesFunction!IteratorSystem(&iterator.removeComponent);
|
gEntityManager.callEntitiesFunction!IteratorSystem(&iterator.removeComponent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Tool.selector:
|
case Tool.selector:
|
||||||
iterator.distance = size2;
|
iterator.distance = size2;
|
||||||
manager.callEntitiesFunction!IteratorSystem(&iterator.selectEntity);
|
gEntityManager.callEntitiesFunction!IteratorSystem(&iterator.selectEntity);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
@ -369,7 +368,7 @@ struct CleanSystem
|
||||||
{
|
{
|
||||||
foreach(i; 0..data.length)
|
foreach(i; 0..data.length)
|
||||||
{
|
{
|
||||||
launcher.manager.removeEntity(data.entities[i].id);
|
gEntityManager.removeEntity(data.entities[i].id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -878,9 +877,9 @@ void mainLoop(void* arg)
|
||||||
//igEndChildFrame();
|
//igEndChildFrame();
|
||||||
if(igButton("Clear",ImVec2(-1,0)))
|
if(igButton("Clear",ImVec2(-1,0)))
|
||||||
{
|
{
|
||||||
launcher.manager.begin();
|
gEntityManager.begin();
|
||||||
launcher.manager.update("clean");
|
gEntityManager.update("clean");
|
||||||
launcher.manager.end();
|
gEntityManager.end();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
igEnd();
|
igEnd();
|
||||||
|
|
@ -1016,10 +1015,11 @@ void mainLoop(void* arg)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
launcher.manager.begin();
|
gEntityManager.begin();
|
||||||
import game_core.rendering;
|
import game_core.rendering;
|
||||||
launcher.manager.callEntitiesFunction!DrawSystem(&(launcher.manager.getSystem!DrawSystem).onUpdate);
|
DrawSystem* draw_system = gEntityManager.getSystem!DrawSystem;
|
||||||
launcher.manager.end();
|
gEntityManager.callEntitiesFunction!DrawSystem(&draw_system.onUpdate);
|
||||||
|
gEntityManager.end();
|
||||||
}
|
}
|
||||||
launcher.job_updater.pool.tryWaitCount = 0;
|
launcher.job_updater.pool.tryWaitCount = 0;
|
||||||
|
|
||||||
|
|
@ -1104,8 +1104,8 @@ void quit()
|
||||||
|
|
||||||
if(launcher.demo.deinitialize)launcher.demo.deinitialize();
|
if(launcher.demo.deinitialize)launcher.demo.deinitialize();
|
||||||
|
|
||||||
launcher.manager.destroy();
|
gEntityManager.destroy();
|
||||||
launcher.manager = null;
|
gEntityManager = null;
|
||||||
|
|
||||||
TexCoordsManager.destroy();
|
TexCoordsManager.destroy();
|
||||||
|
|
||||||
|
|
@ -1231,23 +1231,23 @@ int app_main(int argc, char** argv)
|
||||||
//launcher.job_updater.onCreate();
|
//launcher.job_updater.onCreate();
|
||||||
|
|
||||||
EntityManager.initialize(32, 1<<16);
|
EntityManager.initialize(32, 1<<16);
|
||||||
launcher.manager = gEntityManager;
|
//gEntityManager = gEntityManager;
|
||||||
|
|
||||||
//launcher.manager.m_thread_id_func = &launcher.job_updater.getThreadID;
|
//gEntityManager.m_thread_id_func = &launcher.job_updater.getThreadID;
|
||||||
//launcher.manager.setJobDispachFunc(&launcher.job_updater.dispatch);
|
//gEntityManager.setJobDispachFunc(&launcher.job_updater.dispatch);
|
||||||
launcher.manager.setMultithreadingCallbacks(&launcher.job_updater.dispatch, &launcher.job_updater.getThreadID);
|
gEntityManager.setMultithreadingCallbacks(&launcher.job_updater.dispatch, &launcher.job_updater.getThreadID);
|
||||||
|
|
||||||
launcher.manager.beginRegister();
|
gEntityManager.beginRegister();
|
||||||
|
|
||||||
launcher.manager.registerPass("clean");
|
gEntityManager.registerPass("clean");
|
||||||
|
|
||||||
launcher.manager.registerComponent!CLocation;
|
gEntityManager.registerComponent!CLocation;
|
||||||
|
|
||||||
launcher.manager.registerSystem!CountSystem(10000);
|
gEntityManager.registerSystem!CountSystem(10000);
|
||||||
launcher.manager.registerSystem!CleanSystem(0,"clean");
|
gEntityManager.registerSystem!CleanSystem(0,"clean");
|
||||||
launcher.manager.registerSystem!IteratorSystem(0,"clean");
|
gEntityManager.registerSystem!IteratorSystem(0,"clean");
|
||||||
|
|
||||||
launcher.manager.endRegister();
|
gEntityManager.endRegister();
|
||||||
|
|
||||||
loadGFX();
|
loadGFX();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -193,7 +193,7 @@ struct BallCollisionSystem
|
||||||
bool test(EntityID id)
|
bool test(EntityID id)
|
||||||
{
|
{
|
||||||
if(id == data.entity[i].id)return true;
|
if(id == data.entity[i].id)return true;
|
||||||
Entity* entity = launcher.manager.getEntity(id);
|
Entity* entity = gEntityManager.getEntity(id);
|
||||||
if(entity)
|
if(entity)
|
||||||
{
|
{
|
||||||
CLocation* location = entity.getComponent!CLocation;
|
CLocation* location = entity.getComponent!CLocation;
|
||||||
|
|
@ -224,7 +224,7 @@ struct BallCollisionSystem
|
||||||
{
|
{
|
||||||
vector = vector / sqrtf(pow_dist);
|
vector = vector / sqrtf(pow_dist);
|
||||||
data.velocity[i] = data.velocity[i] - vector * (2 * dot(vector, data.velocity[i]));
|
data.velocity[i] = data.velocity[i] - vector * (2 * dot(vector, data.velocity[i]));
|
||||||
launcher.manager.sendEvent(id,EDamage(1));
|
gEntityManager.sendEvent(id,EDamage(1));
|
||||||
return cast(bool)(hits--);
|
return cast(bool)(hits--);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -243,35 +243,20 @@ struct BallCollisionSystem
|
||||||
|
|
||||||
bool onBegin()
|
bool onBegin()
|
||||||
{
|
{
|
||||||
//grid = launcher.manager.getSystem!ShootGridManager().grid;
|
tree = gEntityManager.getSystem!BVHBuilder().tree;
|
||||||
tree = launcher.manager.getSystem!BVHBuilder().tree;
|
static_tree = gEntityManager.getSystem!StaticBVHBuilder().tree;
|
||||||
static_tree = launcher.manager.getSystem!StaticBVHBuilder().tree;
|
|
||||||
//if(grid is null)return false;
|
|
||||||
if(tree is null || static_tree is null)return false;
|
if(tree is null || static_tree is null)return false;
|
||||||
else return true;
|
else return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void onUpdate(EntitiesData data)
|
void onUpdate(EntitiesData data)
|
||||||
{
|
{
|
||||||
// State state;
|
|
||||||
// state.data = data;
|
|
||||||
// EntityID id;
|
|
||||||
// foreach(i; 0..data.length)
|
|
||||||
// {
|
|
||||||
// state.i = i;
|
|
||||||
// float radius = data.scale[i].x;
|
|
||||||
// if(grid.test(id, data.location[i] - radius, data.location[i] + radius, ubyte.max))
|
|
||||||
// {
|
|
||||||
// state.test(id);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
State state;
|
State state;
|
||||||
state.data = data;
|
state.data = data;
|
||||||
foreach(i; 0..data.length)
|
foreach(i; 0..data.length)
|
||||||
{
|
{
|
||||||
state.i = i;
|
state.i = i;
|
||||||
state.hits = 1;
|
state.hits = 1;
|
||||||
//float radius = data.scale[i].x;
|
|
||||||
AABB bounding = AABB(data.location[i]-data.scale[i], data.location[i]+data.scale[i]);
|
AABB bounding = AABB(data.location[i]-data.scale[i], data.location[i]+data.scale[i]);
|
||||||
tree.test(bounding, cast(bool delegate(EntityID id))&state.test);
|
tree.test(bounding, cast(bool delegate(EntityID id))&state.test);
|
||||||
static_tree.test(bounding, cast(bool delegate(EntityID id))&state.test);
|
static_tree.test(bounding, cast(bool delegate(EntityID id))&state.test);
|
||||||
|
|
@ -298,7 +283,7 @@ struct DamageSystem
|
||||||
EntityMeta meta = entity.getMeta();
|
EntityMeta meta = entity.getMeta();
|
||||||
CHitPoints* hp = meta.getComponent!CHitPoints;
|
CHitPoints* hp = meta.getComponent!CHitPoints;
|
||||||
hp.value -= event.damage;
|
hp.value -= event.damage;
|
||||||
if(hp.value < 0)launcher.manager.removeEntity(entity.id);
|
if(hp.value < 0)gEntityManager.removeEntity(entity.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -328,46 +313,46 @@ void brickBreakerRegister()
|
||||||
demo.texture.create();
|
demo.texture.create();
|
||||||
demo.texture.load("assets/textures/atlas.png");
|
demo.texture.load("assets/textures/atlas.png");
|
||||||
|
|
||||||
launcher.manager.beginRegister();
|
gEntityManager.beginRegister();
|
||||||
|
|
||||||
registerRenderingModule(launcher.manager);
|
registerRenderingModule(gEntityManager);
|
||||||
registerCollisionModule(launcher.manager);
|
registerCollisionModule(gEntityManager);
|
||||||
|
|
||||||
launcher.manager.registerComponent!CLocation;
|
gEntityManager.registerComponent!CLocation;
|
||||||
launcher.manager.registerComponent!CRotation;
|
gEntityManager.registerComponent!CRotation;
|
||||||
launcher.manager.registerComponent!CScale;
|
gEntityManager.registerComponent!CScale;
|
||||||
launcher.manager.registerComponent!CTexCoords;
|
gEntityManager.registerComponent!CTexCoords;
|
||||||
launcher.manager.registerComponent!CTexCoordsIndex;
|
gEntityManager.registerComponent!CTexCoordsIndex;
|
||||||
launcher.manager.registerComponent!CVelocity;
|
gEntityManager.registerComponent!CVelocity;
|
||||||
launcher.manager.registerComponent!CInput;
|
gEntityManager.registerComponent!CInput;
|
||||||
launcher.manager.registerComponent!CPaddle;
|
gEntityManager.registerComponent!CPaddle;
|
||||||
launcher.manager.registerComponent!CDamping;
|
gEntityManager.registerComponent!CDamping;
|
||||||
launcher.manager.registerComponent!CVelocityFactor;
|
gEntityManager.registerComponent!CVelocityFactor;
|
||||||
launcher.manager.registerComponent!CBall;
|
gEntityManager.registerComponent!CBall;
|
||||||
launcher.manager.registerComponent!CHitPoints;
|
gEntityManager.registerComponent!CHitPoints;
|
||||||
|
|
||||||
launcher.manager.registerEvent!EDamage;
|
gEntityManager.registerEvent!EDamage;
|
||||||
|
|
||||||
launcher.manager.registerSystem!MoveSystem(-100);
|
gEntityManager.registerSystem!MoveSystem(-100);
|
||||||
launcher.manager.registerSystem!EdgeCollisionSystem(-99);
|
gEntityManager.registerSystem!EdgeCollisionSystem(-99);
|
||||||
launcher.manager.registerSystem!BallCollisionSystem(-79);
|
gEntityManager.registerSystem!BallCollisionSystem(-79);
|
||||||
launcher.manager.registerSystem!InputMovementSystem(-120);
|
gEntityManager.registerSystem!InputMovementSystem(-120);
|
||||||
launcher.manager.registerSystem!DampingSystem(-120);
|
gEntityManager.registerSystem!DampingSystem(-120);
|
||||||
launcher.manager.registerSystem!DamageSystem(-120);
|
gEntityManager.registerSystem!DamageSystem(-120);
|
||||||
|
|
||||||
launcher.manager.endRegister();
|
gEntityManager.endRegister();
|
||||||
}
|
}
|
||||||
|
|
||||||
void brickBreakerStart()
|
void brickBreakerStart()
|
||||||
{
|
{
|
||||||
DrawSystem* draw_system = launcher.manager.getSystem!DrawSystem;
|
DrawSystem* draw_system = gEntityManager.getSystem!DrawSystem;
|
||||||
draw_system.default_data.color = 0x80808080;
|
draw_system.default_data.color = 0x80808080;
|
||||||
draw_system.default_data.texture = demo.texture;
|
draw_system.default_data.texture = demo.texture;
|
||||||
draw_system.default_data.size = vec2(16,16);
|
draw_system.default_data.size = vec2(16,16);
|
||||||
draw_system.default_data.coords = vec4(246,64,2,2)*px;
|
draw_system.default_data.coords = vec4(246,64,2,2)*px;
|
||||||
draw_system.default_data.material_id = 0;
|
draw_system.default_data.material_id = 0;
|
||||||
|
|
||||||
EntityTemplate* brick_tmpl = launcher.manager.allocateTemplate(
|
EntityTemplate* brick_tmpl = gEntityManager.allocateTemplate(
|
||||||
[becsID!CLocation, becsID!CScale, becsID!CColor,
|
[becsID!CLocation, becsID!CScale, becsID!CColor,
|
||||||
becsID!CTexCoordsIndex, becsID!CBVH, becsID!CHitPoints,
|
becsID!CTexCoordsIndex, becsID!CBVH, becsID!CHitPoints,
|
||||||
becsID!CAABB, becsID!CStatic].staticArray
|
becsID!CAABB, becsID!CStatic].staticArray
|
||||||
|
|
@ -378,11 +363,11 @@ void brickBreakerStart()
|
||||||
brick_tmpl.getComponent!CHitPoints().value = 2;
|
brick_tmpl.getComponent!CHitPoints().value = 2;
|
||||||
//brick_tmpl.getComponent!CAABB().bounding = AABB(vec2(),vec2());
|
//brick_tmpl.getComponent!CAABB().bounding = AABB(vec2(),vec2());
|
||||||
|
|
||||||
EntityTemplate* big_brick_tmpl = launcher.manager.allocateTemplate(brick_tmpl);
|
EntityTemplate* big_brick_tmpl = gEntityManager.allocateTemplate(brick_tmpl);
|
||||||
big_brick_tmpl.getComponent!CTexCoordsIndex().value = TexCoordsManager.instance.getCoordIndex(vec4(320,32,16,16)*px);
|
big_brick_tmpl.getComponent!CTexCoordsIndex().value = TexCoordsManager.instance.getCoordIndex(vec4(320,32,16,16)*px);
|
||||||
big_brick_tmpl.getComponent!CScale().value = vec2(16,16);
|
big_brick_tmpl.getComponent!CScale().value = vec2(16,16);
|
||||||
|
|
||||||
EntityTemplate* paddle_tmpl = launcher.manager.allocateTemplate(
|
EntityTemplate* paddle_tmpl = gEntityManager.allocateTemplate(
|
||||||
[becsID!CLocation, becsID!CScale, becsID!CInput,
|
[becsID!CLocation, becsID!CScale, becsID!CInput,
|
||||||
becsID!CTexCoordsIndex, becsID!CPaddle, becsID!CVelocity,
|
becsID!CTexCoordsIndex, becsID!CPaddle, becsID!CVelocity,
|
||||||
becsID!CDamping, becsID!CVelocityFactor, becsID!CBVH,
|
becsID!CDamping, becsID!CVelocityFactor, becsID!CBVH,
|
||||||
|
|
@ -393,7 +378,7 @@ void brickBreakerStart()
|
||||||
paddle_tmpl.getComponent!CDamping().value = 14;
|
paddle_tmpl.getComponent!CDamping().value = 14;
|
||||||
paddle_tmpl.getComponent!CVelocityFactor().value = vec2(1,0);
|
paddle_tmpl.getComponent!CVelocityFactor().value = vec2(1,0);
|
||||||
|
|
||||||
EntityTemplate* ball_tmpl = launcher.manager.allocateTemplate(
|
EntityTemplate* ball_tmpl = gEntityManager.allocateTemplate(
|
||||||
[becsID!CLocation, becsID!CScale, //becsID!CDamping,
|
[becsID!CLocation, becsID!CScale, //becsID!CDamping,
|
||||||
becsID!CTexCoordsIndex, becsID!CBall, becsID!CVelocity].staticArray
|
becsID!CTexCoordsIndex, becsID!CBall, becsID!CVelocity].staticArray
|
||||||
);
|
);
|
||||||
|
|
@ -446,12 +431,12 @@ void brickBreakerStart()
|
||||||
}
|
}
|
||||||
foreach (j; 0..20)
|
foreach (j; 0..20)
|
||||||
{
|
{
|
||||||
launcher.manager.addEntity(brick_tmpl,[CLocation(vec2(j*18,300-i*10)).ref_, color.ref_].staticArray);
|
gEntityManager.addEntity(brick_tmpl,[CLocation(vec2(j*18,300-i*10)).ref_, color.ref_].staticArray);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
launcher.manager.addEntity(paddle_tmpl,[CLocation(vec2(190,20)).ref_].staticArray);
|
gEntityManager.addEntity(paddle_tmpl,[CLocation(vec2(190,20)).ref_].staticArray);
|
||||||
launcher.manager.addEntity(ball_tmpl,[CLocation(vec2(190,40)).ref_].staticArray);
|
gEntityManager.addEntity(ball_tmpl,[CLocation(vec2(190,40)).ref_].staticArray);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -470,18 +455,18 @@ bool brickBreakerLoop()
|
||||||
{
|
{
|
||||||
launcher.render_position = (vec2(launcher.window_size.x,launcher.window_size.y)*launcher.scalling - vec2(400,300)) * 0.5;
|
launcher.render_position = (vec2(launcher.window_size.x,launcher.window_size.y)*launcher.scalling - vec2(400,300)) * 0.5;
|
||||||
|
|
||||||
launcher.manager.begin();
|
gEntityManager.begin();
|
||||||
if(launcher.multithreading)
|
if(launcher.multithreading)
|
||||||
{
|
{
|
||||||
launcher.job_updater.begin();
|
launcher.job_updater.begin();
|
||||||
launcher.manager.updateMT();
|
gEntityManager.updateMT();
|
||||||
launcher.job_updater.call();
|
launcher.job_updater.call();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
launcher.manager.update();
|
gEntityManager.update();
|
||||||
}
|
}
|
||||||
launcher.manager.end();
|
gEntityManager.end();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -116,74 +116,6 @@ struct CParticleLife
|
||||||
/*#######################################################################################################################
|
/*#######################################################################################################################
|
||||||
------------------------------------------------ Systems ------------------------------------------------------------------
|
------------------------------------------------ Systems ------------------------------------------------------------------
|
||||||
#######################################################################################################################*/
|
#######################################################################################################################*/
|
||||||
/*
|
|
||||||
struct DrawSystem
|
|
||||||
{
|
|
||||||
mixin ECS.System!32;
|
|
||||||
|
|
||||||
struct EntitiesData
|
|
||||||
{
|
|
||||||
uint length;
|
|
||||||
//uint thread_id;
|
|
||||||
uint job_id;
|
|
||||||
//@readonly CTexCoords[] coords;
|
|
||||||
@readonly CLocation[] locations;
|
|
||||||
|
|
||||||
@optional @readonly CColor[] color;
|
|
||||||
}
|
|
||||||
|
|
||||||
void onUpdate(EntitiesData data)
|
|
||||||
{
|
|
||||||
if(launcher.renderer.prepared_items >= launcher.renderer.MaxObjects)return;//simple leave loop if max visible objects count was reached
|
|
||||||
import ecs_utils.gfx.renderer;
|
|
||||||
Renderer.DrawData draw_data;
|
|
||||||
draw_data.size = vec2(2,2);
|
|
||||||
draw_data.coords = vec4(246,64,2,2)*px;
|
|
||||||
draw_data.color = 0x80808080;
|
|
||||||
draw_data.material_id = 2;
|
|
||||||
draw_data.thread_id = data.job_id;
|
|
||||||
draw_data.texture = particles_demo.texture;
|
|
||||||
|
|
||||||
if(!data.color)
|
|
||||||
{
|
|
||||||
foreach(i; 0..data.length)
|
|
||||||
{
|
|
||||||
draw_data.position = data.locations[i];
|
|
||||||
launcher.renderer.draw(draw_data);//particles_demo.texture, data.locations[i], vec2(2,2), vec4(246,64,2,2)*px, 0, 0x80808080, 0, 2, 0, data.job_id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
foreach(i; 0..data.length)
|
|
||||||
{
|
|
||||||
draw_data.position = data.locations[i];
|
|
||||||
draw_data.color = data.color[i].value;
|
|
||||||
launcher.renderer.draw(draw_data);//particles_demo.texture, data.locations[i], vec2(2,2), vec4(246,64,2,2)*px, 0, data.color[i].value, 0, 2, 0, data.job_id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
// struct MoveSystem
|
|
||||||
// {
|
|
||||||
// mixin ECS.System!64;
|
|
||||||
|
|
||||||
// struct EntitiesData
|
|
||||||
// {
|
|
||||||
// uint length;
|
|
||||||
// CLocation[] locations;
|
|
||||||
// @readonly CVelocity[] velocity;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// void onUpdate(EntitiesData data)
|
|
||||||
// {
|
|
||||||
// foreach(i; 0..data.length)
|
|
||||||
// {
|
|
||||||
// data.locations[i] += data.velocity[i] * launcher.deltaTime;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
struct MouseAttractSystem
|
struct MouseAttractSystem
|
||||||
{
|
{
|
||||||
|
|
@ -296,7 +228,7 @@ struct AttractSystem
|
||||||
{
|
{
|
||||||
Updater updater;
|
Updater updater;
|
||||||
updater.data = data;
|
updater.data = data;
|
||||||
launcher.manager.callEntitiesFunction!AttractorIterator(&updater.onUpdate);
|
gEntityManager.callEntitiesFunction!AttractorIterator(&updater.onUpdate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -339,47 +271,14 @@ struct PlayAreaSystem
|
||||||
{
|
{
|
||||||
foreach(i; 0..data.length)
|
foreach(i; 0..data.length)
|
||||||
{
|
{
|
||||||
if(data.locations[i].x > 440)launcher.manager.removeEntity(data.entity[i].id);
|
if(data.locations[i].x > 440)gEntityManager.removeEntity(data.entity[i].id);
|
||||||
else if(data.locations[i].x < -40)launcher.manager.removeEntity(data.entity[i].id);
|
else if(data.locations[i].x < -40)gEntityManager.removeEntity(data.entity[i].id);
|
||||||
if(data.locations[i].y > 340)launcher.manager.removeEntity(data.entity[i].id);
|
if(data.locations[i].y > 340)gEntityManager.removeEntity(data.entity[i].id);
|
||||||
else if(data.locations[i].y < -40)launcher.manager.removeEntity(data.entity[i].id);
|
else if(data.locations[i].y < -40)gEntityManager.removeEntity(data.entity[i].id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// struct DampingSystem
|
|
||||||
// {
|
|
||||||
// mixin ECS.System!32;
|
|
||||||
|
|
||||||
// struct EntitiesData
|
|
||||||
// {
|
|
||||||
// uint length;
|
|
||||||
// const (Entity)[] entity;
|
|
||||||
// @readonly CDamping[] damping;
|
|
||||||
// CVelocity[] velocity;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// float[10] damp = 0;
|
|
||||||
|
|
||||||
// bool onBegin()
|
|
||||||
// {
|
|
||||||
// foreach(i;0..10)
|
|
||||||
// {
|
|
||||||
// damp[i] = powf((0.99 - cast(float)i * 0.01),launcher.deltaTime*0.1);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// void onUpdate(EntitiesData data)
|
|
||||||
// {
|
|
||||||
// foreach(i; 0..data.length)
|
|
||||||
// {
|
|
||||||
// data.velocity[i] = data.velocity[i] * damp[data.damping[i]];
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
struct ParticleLifeSystem
|
struct ParticleLifeSystem
|
||||||
{
|
{
|
||||||
mixin ECS.System!32;
|
mixin ECS.System!32;
|
||||||
|
|
@ -404,7 +303,7 @@ struct ParticleLifeSystem
|
||||||
foreach(i; 0..data.length)
|
foreach(i; 0..data.length)
|
||||||
{
|
{
|
||||||
data.life[i] -= delta_time;
|
data.life[i] -= delta_time;
|
||||||
if(data.life[i] < 0)launcher.manager.removeEntity(data.entity[i].id);
|
if(data.life[i] < 0)gEntityManager.removeEntity(data.entity[i].id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -452,45 +351,45 @@ void particlesRegister()
|
||||||
particles_demo.texture.create();
|
particles_demo.texture.create();
|
||||||
particles_demo.texture.load("assets/textures/atlas.png");
|
particles_demo.texture.load("assets/textures/atlas.png");
|
||||||
|
|
||||||
launcher.manager.beginRegister();
|
gEntityManager.beginRegister();
|
||||||
|
|
||||||
registerRenderingModule(launcher.manager);
|
registerRenderingModule(gEntityManager);
|
||||||
|
|
||||||
launcher.manager.registerComponent!CLocation;
|
gEntityManager.registerComponent!CLocation;
|
||||||
//launcher.manager.registerComponent!CTexCoords;
|
//gEntityManager.registerComponent!CTexCoords;
|
||||||
launcher.manager.registerComponent!CColor;
|
gEntityManager.registerComponent!CColor;
|
||||||
launcher.manager.registerComponent!CVelocity;
|
gEntityManager.registerComponent!CVelocity;
|
||||||
launcher.manager.registerComponent!CScale;
|
gEntityManager.registerComponent!CScale;
|
||||||
launcher.manager.registerComponent!CTexCoords;
|
gEntityManager.registerComponent!CTexCoords;
|
||||||
launcher.manager.registerComponent!CTexCoordsIndex;
|
gEntityManager.registerComponent!CTexCoordsIndex;
|
||||||
launcher.manager.registerComponent!CRotation;
|
gEntityManager.registerComponent!CRotation;
|
||||||
launcher.manager.registerComponent!CDepth;
|
gEntityManager.registerComponent!CDepth;
|
||||||
launcher.manager.registerComponent!CAttractor;
|
gEntityManager.registerComponent!CAttractor;
|
||||||
launcher.manager.registerComponent!CDamping;
|
gEntityManager.registerComponent!CDamping;
|
||||||
launcher.manager.registerComponent!CGravity;
|
gEntityManager.registerComponent!CGravity;
|
||||||
launcher.manager.registerComponent!CVortex;
|
gEntityManager.registerComponent!CVortex;
|
||||||
launcher.manager.registerComponent!CParticleLife;
|
gEntityManager.registerComponent!CParticleLife;
|
||||||
launcher.manager.registerComponent!CForceRange;
|
gEntityManager.registerComponent!CForceRange;
|
||||||
launcher.manager.registerComponent!CMaterialIndex;
|
gEntityManager.registerComponent!CMaterialIndex;
|
||||||
launcher.manager.registerComponent!CVelocityFactor;
|
gEntityManager.registerComponent!CVelocityFactor;
|
||||||
|
|
||||||
launcher.manager.registerSystem!MoveSystem(0);
|
gEntityManager.registerSystem!MoveSystem(0);
|
||||||
launcher.manager.registerSystem!DrawSystem(100);
|
gEntityManager.registerSystem!DrawSystem(100);
|
||||||
launcher.manager.registerSystem!PlayAreaSystem(102);
|
gEntityManager.registerSystem!PlayAreaSystem(102);
|
||||||
launcher.manager.registerSystem!AttractSystem(-1);
|
gEntityManager.registerSystem!AttractSystem(-1);
|
||||||
launcher.manager.registerSystem!MouseAttractSystem(1);
|
gEntityManager.registerSystem!MouseAttractSystem(1);
|
||||||
launcher.manager.registerSystem!DampingSystem(101);
|
gEntityManager.registerSystem!DampingSystem(101);
|
||||||
launcher.manager.registerSystem!ParticleLifeSystem(-10);
|
gEntityManager.registerSystem!ParticleLifeSystem(-10);
|
||||||
launcher.manager.registerSystem!GravitySystem(-2);
|
gEntityManager.registerSystem!GravitySystem(-2);
|
||||||
|
|
||||||
launcher.manager.registerSystem!AttractorIterator(-1);
|
gEntityManager.registerSystem!AttractorIterator(-1);
|
||||||
|
|
||||||
launcher.manager.endRegister();
|
gEntityManager.endRegister();
|
||||||
}
|
}
|
||||||
|
|
||||||
void particlesStart()
|
void particlesStart()
|
||||||
{
|
{
|
||||||
DrawSystem* draw_system = launcher.manager.getSystem!DrawSystem;
|
DrawSystem* draw_system = gEntityManager.getSystem!DrawSystem;
|
||||||
draw_system.default_data.size = vec2(2,2);
|
draw_system.default_data.size = vec2(2,2);
|
||||||
draw_system.default_data.coords = vec4(246,64,2,2)*px;
|
draw_system.default_data.coords = vec4(246,64,2,2)*px;
|
||||||
draw_system.default_data.material_id = 2;
|
draw_system.default_data.material_id = 2;
|
||||||
|
|
@ -518,32 +417,32 @@ void particlesStart()
|
||||||
launcher.gui_manager.addComponent(CGravity(),"Gravity");
|
launcher.gui_manager.addComponent(CGravity(),"Gravity");
|
||||||
|
|
||||||
EntityTemplate* tmpl;
|
EntityTemplate* tmpl;
|
||||||
EntityTemplate* base_tmpl = launcher.manager.allocateTemplate([becsID!CTexCoords, becsID!CLocation, becsID!CColor, becsID!CVelocity, becsID!CDamping, becsID!CScale, becsID!CMaterialIndex].staticArray);
|
EntityTemplate* base_tmpl = gEntityManager.allocateTemplate([becsID!CTexCoords, becsID!CLocation, becsID!CColor, becsID!CVelocity, becsID!CDamping, becsID!CScale, becsID!CMaterialIndex].staticArray);
|
||||||
base_tmpl.getComponent!CColor().value = 0xFF251010;
|
base_tmpl.getComponent!CColor().value = 0xFF251010;
|
||||||
base_tmpl.getComponent!CScale().value = vec2(2);
|
base_tmpl.getComponent!CScale().value = vec2(2);
|
||||||
base_tmpl.getComponent!CTexCoords().value = vec4(246,64,2,2)*px;
|
base_tmpl.getComponent!CTexCoords().value = vec4(246,64,2,2)*px;
|
||||||
base_tmpl.getComponent!CMaterialIndex().value = 2;
|
base_tmpl.getComponent!CMaterialIndex().value = 2;
|
||||||
launcher.gui_manager.addTemplate(base_tmpl,"Particle");
|
launcher.gui_manager.addTemplate(base_tmpl,"Particle");
|
||||||
// tmpl = launcher.manager.allocateTemplate(base_tmpl);
|
// tmpl = gEntityManager.allocateTemplate(base_tmpl);
|
||||||
// tmpl.getComponent!CColor().value = 0xFF251010;
|
// tmpl.getComponent!CColor().value = 0xFF251010;
|
||||||
// launcher.gui_manager.addTemplate(tmpl,"Particle (blue)");
|
// launcher.gui_manager.addTemplate(tmpl,"Particle (blue)");
|
||||||
// tmpl = launcher.manager.allocateTemplate(base_tmpl);
|
// tmpl = gEntityManager.allocateTemplate(base_tmpl);
|
||||||
// tmpl.getComponent!CColor().value = 0xFF102010;
|
// tmpl.getComponent!CColor().value = 0xFF102010;
|
||||||
// launcher.gui_manager.addTemplate(tmpl,"Particle (green)");
|
// launcher.gui_manager.addTemplate(tmpl,"Particle (green)");
|
||||||
// tmpl = launcher.manager.allocateTemplate(base_tmpl);
|
// tmpl = gEntityManager.allocateTemplate(base_tmpl);
|
||||||
// tmpl.getComponent!CColor().value = 0xFF101540;
|
// tmpl.getComponent!CColor().value = 0xFF101540;
|
||||||
// launcher.gui_manager.addTemplate(tmpl,"Particle (red)");
|
// launcher.gui_manager.addTemplate(tmpl,"Particle (red)");
|
||||||
// tmpl = launcher.manager.allocateTemplate(tmpl, [becsID!CDamping].staticArray);
|
// tmpl = gEntityManager.allocateTemplate(tmpl, [becsID!CDamping].staticArray);
|
||||||
// launcher.gui_manager.addTemplate(tmpl,"Particle (damping)");
|
// launcher.gui_manager.addTemplate(tmpl,"Particle (damping)");
|
||||||
// tmpl = launcher.manager.allocateTemplate(tmpl);
|
// tmpl = gEntityManager.allocateTemplate(tmpl);
|
||||||
// tmpl.getComponent!CDamping().power = 4;
|
// tmpl.getComponent!CDamping().power = 4;
|
||||||
// launcher.gui_manager.addTemplate(tmpl,"Particle (damping!)");
|
// launcher.gui_manager.addTemplate(tmpl,"Particle (damping!)");
|
||||||
tmpl = launcher.manager.allocateTemplate([becsID!CAttractor, becsID!CLocation, becsID!CForceRange, becsID!CScale].staticArray);
|
tmpl = gEntityManager.allocateTemplate([becsID!CAttractor, becsID!CLocation, becsID!CForceRange, becsID!CScale].staticArray);
|
||||||
tmpl.getComponent!CScale().value = vec2(4);
|
tmpl.getComponent!CScale().value = vec2(4);
|
||||||
launcher.gui_manager.addTemplate(tmpl,"Attractor");
|
launcher.gui_manager.addTemplate(tmpl,"Attractor");
|
||||||
tmpl = launcher.manager.allocateTemplate(tmpl, [becsID!CVortex].staticArray);
|
tmpl = gEntityManager.allocateTemplate(tmpl, [becsID!CVortex].staticArray);
|
||||||
launcher.gui_manager.addTemplate(tmpl,"Vortex");
|
launcher.gui_manager.addTemplate(tmpl,"Vortex");
|
||||||
// tmpl = launcher.manager.allocateTemplate(tmpl);
|
// tmpl = gEntityManager.allocateTemplate(tmpl);
|
||||||
// tmpl.getComponent!CVortex().strength = -0.6;
|
// tmpl.getComponent!CVortex().strength = -0.6;
|
||||||
// launcher.gui_manager.addTemplate(tmpl,"Vortex (reversed)");
|
// launcher.gui_manager.addTemplate(tmpl,"Vortex (reversed)");
|
||||||
|
|
||||||
|
|
@ -553,7 +452,7 @@ void particlesEnd()
|
||||||
{
|
{
|
||||||
particles_demo.texture.destroy();
|
particles_demo.texture.destroy();
|
||||||
|
|
||||||
//launcher.manager.freeTemplate(simple.tmpl);
|
//gEntityManager.freeTemplate(simple.tmpl);
|
||||||
Mallocator.dispose(particles_demo);
|
Mallocator.dispose(particles_demo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -565,18 +464,18 @@ bool particlesLoop()
|
||||||
{
|
{
|
||||||
launcher.render_position = (vec2(launcher.window_size.x,launcher.window_size.y)*launcher.scalling - vec2(400,300)) * 0.5;
|
launcher.render_position = (vec2(launcher.window_size.x,launcher.window_size.y)*launcher.scalling - vec2(400,300)) * 0.5;
|
||||||
|
|
||||||
launcher.manager.begin();
|
gEntityManager.begin();
|
||||||
if(launcher.multithreading)
|
if(launcher.multithreading)
|
||||||
{
|
{
|
||||||
launcher.job_updater.begin();
|
launcher.job_updater.begin();
|
||||||
launcher.manager.updateMT();
|
gEntityManager.updateMT();
|
||||||
launcher.job_updater.call();
|
launcher.job_updater.call();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
launcher.manager.update();
|
gEntityManager.update();
|
||||||
}
|
}
|
||||||
launcher.manager.end();
|
gEntityManager.end();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,15 +32,15 @@ void sandboxStart()
|
||||||
particlesStart();
|
particlesStart();
|
||||||
brickBreakerStart();
|
brickBreakerStart();
|
||||||
|
|
||||||
DrawSystem* draw_system = launcher.manager.getSystem!DrawSystem;
|
DrawSystem* draw_system = gEntityManager.getSystem!DrawSystem;
|
||||||
draw_system.default_data.size = vec2(16,16);
|
draw_system.default_data.size = vec2(16,16);
|
||||||
draw_system.default_data.coords = vec4(0,48,16,16)*demos.simple.px;
|
draw_system.default_data.coords = vec4(0,48,16,16)*demos.simple.px;
|
||||||
draw_system.default_data.material_id = 0;
|
draw_system.default_data.material_id = 0;
|
||||||
draw_system.default_data.texture = particles_demo.texture;
|
draw_system.default_data.texture = particles_demo.texture;
|
||||||
draw_system.default_data.color = 0x80808080;
|
draw_system.default_data.color = 0x80808080;
|
||||||
|
|
||||||
launcher.manager.getSystem(becsID!MouseAttractSystem).disable();
|
gEntityManager.getSystem(becsID!MouseAttractSystem).disable();
|
||||||
launcher.manager.getSystem(becsID!(demos.simple.MoveSystem)).disable();
|
gEntityManager.getSystem(becsID!(demos.simple.MoveSystem)).disable();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -60,7 +60,7 @@ bool sandboxLoop()
|
||||||
{
|
{
|
||||||
launcher.render_position = (vec2(launcher.window_size.x,launcher.window_size.y)*launcher.scalling - vec2(400,300)) * 0.5;
|
launcher.render_position = (vec2(launcher.window_size.x,launcher.window_size.y)*launcher.scalling - vec2(400,300)) * 0.5;
|
||||||
|
|
||||||
launcher.manager.begin();
|
gEntityManager.begin();
|
||||||
|
|
||||||
float delta_time = launcher.delta_time;
|
float delta_time = launcher.delta_time;
|
||||||
if(delta_time > 2000)delta_time = 2000;
|
if(delta_time > 2000)delta_time = 2000;
|
||||||
|
|
@ -74,20 +74,20 @@ bool sandboxLoop()
|
||||||
{
|
{
|
||||||
time -= 200;
|
time -= 200;
|
||||||
|
|
||||||
launcher.manager.update("fixed");
|
gEntityManager.update("fixed");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(launcher.multithreading)
|
if(launcher.multithreading)
|
||||||
{
|
{
|
||||||
launcher.job_updater.begin();
|
launcher.job_updater.begin();
|
||||||
launcher.manager.updateMT();
|
gEntityManager.updateMT();
|
||||||
launcher.job_updater.call();
|
launcher.job_updater.call();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
launcher.manager.update();
|
gEntityManager.update();
|
||||||
}
|
}
|
||||||
launcher.manager.end();
|
gEntityManager.end();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,10 +23,22 @@ extern(C):
|
||||||
|
|
||||||
enum float px = 1.0/512.0;
|
enum float px = 1.0/512.0;
|
||||||
|
|
||||||
|
/**************************************************
|
||||||
|
All demos uses same patten. Every demo is self contained except systems and components which was splitted into different files to enable sharing them between demos.
|
||||||
|
Every demo has same functions:
|
||||||
|
* register - called on start for registering proces
|
||||||
|
* initialize - called after register to initialize demo data
|
||||||
|
* deinitiliaze - called when demo is switching. There data is deisposed
|
||||||
|
* loop - it's called every frame
|
||||||
|
|
||||||
|
Demos uses some non-ECS functions to register components, systems and templates into GUI. Then components are showing by GUI and can be added to entities.
|
||||||
|
*/
|
||||||
|
|
||||||
/*#######################################################################################################################
|
/*#######################################################################################################################
|
||||||
------------------------------------------------ Components ------------------------------------------------------------------
|
------------------------------------------------ Components ------------------------------------------------------------------
|
||||||
#######################################################################################################################*/
|
#######################################################################################################################*/
|
||||||
|
|
||||||
|
//CLocation component was moved to game_code.basic
|
||||||
/*struct CLocation
|
/*struct CLocation
|
||||||
{
|
{
|
||||||
mixin ECS.Component;
|
mixin ECS.Component;
|
||||||
|
|
@ -39,6 +51,7 @@ enum float px = 1.0/512.0;
|
||||||
/*#######################################################################################################################
|
/*#######################################################################################################################
|
||||||
------------------------------------------------ Systems ------------------------------------------------------------------
|
------------------------------------------------ Systems ------------------------------------------------------------------
|
||||||
#######################################################################################################################*/
|
#######################################################################################################################*/
|
||||||
|
//DrawSystem was moved to game_code.basic
|
||||||
/*
|
/*
|
||||||
struct DrawSystem
|
struct DrawSystem
|
||||||
{
|
{
|
||||||
|
|
@ -73,21 +86,29 @@ struct DrawSystem
|
||||||
}
|
}
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
|
//simple system which moves entities
|
||||||
struct MoveSystem
|
struct MoveSystem
|
||||||
{
|
{
|
||||||
|
//system will generate up to 64 jobs for multithreaded extecution
|
||||||
mixin ECS.System!64;
|
mixin ECS.System!64;
|
||||||
|
|
||||||
|
//structe contains components used by system
|
||||||
struct EntitiesData
|
struct EntitiesData
|
||||||
{
|
{
|
||||||
uint length;
|
uint length;
|
||||||
|
//system will use one component which is required. Only entities with CLocation component will be processed by this system
|
||||||
CLocation[] locations;
|
CLocation[] locations;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//onUpdate is called several times and covers all entities
|
||||||
void onUpdate(EntitiesData data)
|
void onUpdate(EntitiesData data)
|
||||||
{
|
{
|
||||||
|
//loop over entities in batch
|
||||||
foreach(i; 0..data.length)
|
foreach(i; 0..data.length)
|
||||||
{
|
{
|
||||||
|
//inscrease entity position in 'y' coordinate
|
||||||
data.locations[i].y = data.locations[i].y + 1;
|
data.locations[i].y = data.locations[i].y + 1;
|
||||||
|
//move entity to 0 if exceeded 300
|
||||||
if(data.locations[i].y > 300)data.locations[i].y = 0;
|
if(data.locations[i].y > 300)data.locations[i].y = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -99,6 +120,7 @@ struct MoveSystem
|
||||||
|
|
||||||
struct Simple
|
struct Simple
|
||||||
{
|
{
|
||||||
|
//tips showed in GUI
|
||||||
__gshared const (char)* tips = "Use \"space\" to spwan entities.\n\nSystems can be enabled/disabled from \"Demo\" window.
|
__gshared const (char)* tips = "Use \"space\" to spwan entities.\n\nSystems can be enabled/disabled from \"Demo\" window.
|
||||||
\"Tools\" window exists of three tools which can be used to manipulate game.
|
\"Tools\" window exists of three tools which can be used to manipulate game.
|
||||||
Options:
|
Options:
|
||||||
|
|
@ -132,61 +154,77 @@ Demo is capable rendering of hundreds of thousands of entities. Playable area is
|
||||||
|
|
||||||
__gshared Simple* simple;
|
__gshared Simple* simple;
|
||||||
|
|
||||||
|
//called when demo starts
|
||||||
void simpleRegister()
|
void simpleRegister()
|
||||||
{
|
{
|
||||||
simple = Mallocator.make!Simple;
|
simple = Mallocator.make!Simple;
|
||||||
|
|
||||||
|
//load texture (atlas)
|
||||||
simple.texture.create();
|
simple.texture.create();
|
||||||
simple.texture.load("assets/textures/atlas.png");
|
simple.texture.load("assets/textures/atlas.png");
|
||||||
|
|
||||||
launcher.manager.beginRegister();
|
//start registering process
|
||||||
|
gEntityManager.beginRegister();
|
||||||
|
|
||||||
registerRenderingModule(launcher.manager);
|
//register basic components and systems
|
||||||
|
registerRenderingModule(gEntityManager);
|
||||||
|
|
||||||
launcher.manager.registerComponent!CLocation;
|
//register location component. It also registered inside registerRenderingModule() function, but it's there for clarity
|
||||||
|
gEntityManager.registerComponent!CLocation;
|
||||||
|
|
||||||
launcher.manager.registerSystem!MoveSystem(0);
|
gEntityManager.registerSystem!MoveSystem(0);
|
||||||
// launcher.manager.registerSystem!DrawSystem(1);
|
// DrawSystem is registered as RenderingModule
|
||||||
|
// gEntityManager.registerSystem!DrawSystem(1);
|
||||||
|
|
||||||
launcher.manager.endRegister();
|
//end registering process
|
||||||
|
gEntityManager.endRegister();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//called after simpleRegister
|
||||||
void simpleStart()
|
void simpleStart()
|
||||||
{
|
{
|
||||||
DrawSystem* draw_system = launcher.manager.getSystem!DrawSystem;
|
//get DrawSystem instance and change some data
|
||||||
|
DrawSystem* draw_system = gEntityManager.getSystem!DrawSystem;
|
||||||
draw_system.default_data.color = 0x80808080;
|
draw_system.default_data.color = 0x80808080;
|
||||||
draw_system.default_data.texture = simple.texture;
|
draw_system.default_data.texture = simple.texture;
|
||||||
draw_system.default_data.size = vec2(16,16);
|
draw_system.default_data.size = vec2(16,16);
|
||||||
draw_system.default_data.coords = vec4(0,48,16,16)*px;//vec4(0,0,1,1);
|
draw_system.default_data.coords = vec4(0,48,16,16)*px;//vec4(0,0,1,1);
|
||||||
|
|
||||||
|
//add systems to GUI. It's non ECS part
|
||||||
launcher.gui_manager.addSystem(becsID!MoveSystem,"Move Up System");
|
launcher.gui_manager.addSystem(becsID!MoveSystem,"Move Up System");
|
||||||
launcher.gui_manager.addSystem(becsID!DrawSystem,"Draw System");
|
launcher.gui_manager.addSystem(becsID!DrawSystem,"Draw System");
|
||||||
|
|
||||||
|
//add components to GUI. It's non ECS part
|
||||||
launcher.gui_manager.addComponent(CLocation(), "Location");
|
launcher.gui_manager.addComponent(CLocation(), "Location");
|
||||||
launcher.gui_manager.addComponent(CDrawDefault(), "DrawDefault");
|
launcher.gui_manager.addComponent(CDrawDefault(), "DrawDefault");
|
||||||
|
|
||||||
simple.tmpl = launcher.manager.allocateTemplate([becsID!CLocation, becsID!CDrawDefault].staticArray);
|
//allocate new template with two components
|
||||||
//*simple.tmpl.getComponent!CTexCoordsIndex = TexCoordsManager.instance.getCoordIndex(vec4(0,48,16,16)*px);
|
simple.tmpl = gEntityManager.allocateTemplate([becsID!CLocation, becsID!CDrawDefault].staticArray);
|
||||||
//CLocation* loc_comp = simple.tmpl.getComponent!CLocation;
|
|
||||||
|
|
||||||
|
//add template to GUI. It's non ECS part
|
||||||
launcher.gui_manager.addTemplate(simple.tmpl, "Basic");
|
launcher.gui_manager.addTemplate(simple.tmpl, "Basic");
|
||||||
|
|
||||||
|
//add 100 entities
|
||||||
foreach(i; 0..10)
|
foreach(i; 0..10)
|
||||||
foreach(j; 0..10)
|
foreach(j; 0..10)
|
||||||
{
|
{
|
||||||
//loc_comp.value = vec2(i*16+64,j*16+64);
|
//add entities in grid locations. "ref_" return ComponentRef structure. I'm not sure if adding component inside array generation isn't undefined behaviour but it works on tested platforms
|
||||||
launcher.manager.addEntity(simple.tmpl,[CLocation(vec2(i*16+64,j*16+64)).ref_].staticArray);
|
gEntityManager.addEntity(simple.tmpl,[CLocation(vec2(i*16+64,j*16+64)).ref_].staticArray);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//called when demo is switched to different one
|
||||||
void simpleEnd()
|
void simpleEnd()
|
||||||
{
|
{
|
||||||
launcher.manager.getSystem(becsID!MoveSystem).disable();
|
//disable systems used by this demo.
|
||||||
launcher.manager.getSystem(becsID!DrawSystem).disable();
|
gEntityManager.getSystem(becsID!MoveSystem).disable();
|
||||||
|
gEntityManager.getSystem(becsID!DrawSystem).disable();
|
||||||
|
|
||||||
|
//free texture memory
|
||||||
simple.texture.destroy();
|
simple.texture.destroy();
|
||||||
|
|
||||||
//launcher.manager.freeTemplate(simple.tmpl);
|
//GUI manager will free template
|
||||||
|
//gEntityManager.freeTemplate(simple.tmpl);
|
||||||
Mallocator.dispose(simple);
|
Mallocator.dispose(simple);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -196,9 +234,8 @@ void simpleEvent(SDL_Event* event)
|
||||||
|
|
||||||
void spawnEntity()
|
void spawnEntity()
|
||||||
{
|
{
|
||||||
//CLocation* loc_comp = simple.tmpl.getComponent!CLocation;
|
//spawn entity in random location
|
||||||
//loc_comp.value = vec2(randomf() * 400,0);
|
gEntityManager.addEntity(simple.tmpl,[CLocation(vec2(randomf() * 400,0)).ref_].staticArray);
|
||||||
launcher.manager.addEntity(simple.tmpl,[CLocation(vec2(randomf() * 400,0)).ref_].staticArray);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool simpleLoop()
|
bool simpleLoop()
|
||||||
|
|
@ -210,18 +247,26 @@ bool simpleLoop()
|
||||||
foreach(i;0..20)spawnEntity();
|
foreach(i;0..20)spawnEntity();
|
||||||
}
|
}
|
||||||
|
|
||||||
launcher.manager.begin();
|
//begin frame
|
||||||
|
gEntityManager.begin();
|
||||||
|
//if multithreading is enabled different path is used
|
||||||
if(launcher.multithreading)
|
if(launcher.multithreading)
|
||||||
{
|
{
|
||||||
|
//prepare data for multithreading. Clear previous jobs data.
|
||||||
launcher.job_updater.begin();
|
launcher.job_updater.begin();
|
||||||
launcher.manager.updateMT();
|
//generate jobs
|
||||||
|
gEntityManager.updateMT();
|
||||||
|
//call jobs in multithreaded fashion
|
||||||
launcher.job_updater.call();
|
launcher.job_updater.call();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
launcher.manager.update();
|
//update call will call inUpdate for all systems
|
||||||
|
gEntityManager.update();
|
||||||
|
|
||||||
}
|
}
|
||||||
launcher.manager.end();
|
//end ECS frame
|
||||||
|
gEntityManager.end();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ enum float px = 1.0/512.0;
|
||||||
|
|
||||||
extern(C):
|
extern(C):
|
||||||
|
|
||||||
|
//Map is simple grid. Every cell has type and id to entity.
|
||||||
struct MapElement
|
struct MapElement
|
||||||
{
|
{
|
||||||
enum Type
|
enum Type
|
||||||
|
|
@ -38,6 +39,7 @@ struct MapElement
|
||||||
EntityID id;
|
EntityID id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//snake part is corresponding to graphical representation of snake
|
||||||
enum SnakePart : ubyte
|
enum SnakePart : ubyte
|
||||||
{
|
{
|
||||||
head_up = 0,
|
head_up = 0,
|
||||||
|
|
@ -81,9 +83,9 @@ This demo is an example that in ECS you can make very \"non-ECS\" game";
|
||||||
{
|
{
|
||||||
if(snake_destroy_particle_frames)Mallocator.dispose(snake_destroy_particle_frames);
|
if(snake_destroy_particle_frames)Mallocator.dispose(snake_destroy_particle_frames);
|
||||||
if(smoke_frames)Mallocator.dispose(smoke_frames);
|
if(smoke_frames)Mallocator.dispose(smoke_frames);
|
||||||
if(apple_tmpl)launcher.manager.freeTemplate(apple_tmpl);
|
if(apple_tmpl)gEntityManager.freeTemplate(apple_tmpl);
|
||||||
if(snake_tmpl)launcher.manager.freeTemplate(snake_tmpl);
|
if(snake_tmpl)gEntityManager.freeTemplate(snake_tmpl);
|
||||||
if(snake_destroy_particle)launcher.manager.freeTemplate(snake_destroy_particle);
|
if(snake_destroy_particle)gEntityManager.freeTemplate(snake_destroy_particle);
|
||||||
texture.destroy();
|
texture.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -116,7 +118,7 @@ This demo is an example that in ECS you can make very \"non-ECS\" game";
|
||||||
}
|
}
|
||||||
if(base_pos.x == random_pos.x && base_pos.y == random_pos.y)return;
|
if(base_pos.x == random_pos.x && base_pos.y == random_pos.y)return;
|
||||||
}
|
}
|
||||||
launcher.manager.addEntity(apple_tmpl,[CLocation(cast(vec2)(random_pos)*16).ref_].staticArray);
|
gEntityManager.addEntity(apple_tmpl,[CLocation(cast(vec2)(random_pos)*16).ref_].staticArray);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -125,6 +127,7 @@ struct Animation
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//component has array of frames (texture coordinates) and time used for selection frames
|
||||||
struct CAnimation
|
struct CAnimation
|
||||||
{
|
{
|
||||||
mixin ECS.Component;
|
mixin ECS.Component;
|
||||||
|
|
@ -133,6 +136,7 @@ struct CAnimation
|
||||||
float time = 0;
|
float time = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//CIlocation is integer location used as grid cell coordination
|
||||||
struct CILocation
|
struct CILocation
|
||||||
{
|
{
|
||||||
mixin ECS.Component;
|
mixin ECS.Component;
|
||||||
|
|
@ -202,11 +206,13 @@ struct CSnake
|
||||||
CMovement.Direction direction;
|
CMovement.Direction direction;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//flag for apple
|
||||||
struct CApple
|
struct CApple
|
||||||
{
|
{
|
||||||
mixin ECS.Component;
|
mixin ECS.Component;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//particle is removed when life drops below 0
|
||||||
struct CParticle
|
struct CParticle
|
||||||
{
|
{
|
||||||
mixin ECS.Component;
|
mixin ECS.Component;
|
||||||
|
|
@ -214,6 +220,7 @@ struct CParticle
|
||||||
float life = 0;
|
float life = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//vector for particle movement
|
||||||
struct CParticleVector
|
struct CParticleVector
|
||||||
{
|
{
|
||||||
mixin ECS.Component;
|
mixin ECS.Component;
|
||||||
|
|
@ -221,6 +228,7 @@ struct CParticleVector
|
||||||
vec2 velocity = vec2(0,0);
|
vec2 velocity = vec2(0,0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//contains current movement direction for snake
|
||||||
struct CMovement
|
struct CMovement
|
||||||
{
|
{
|
||||||
mixin ECS.Component;
|
mixin ECS.Component;
|
||||||
|
|
@ -241,6 +249,7 @@ struct CMovement
|
||||||
// mixin ECS.Component;
|
// mixin ECS.Component;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
//this system has no onUpdate and only processing events. It responsible for adding and removing applce from grid.
|
||||||
struct AppleSystem
|
struct AppleSystem
|
||||||
{
|
{
|
||||||
mixin ECS.System!1;
|
mixin ECS.System!1;
|
||||||
|
|
@ -253,15 +262,17 @@ struct AppleSystem
|
||||||
@readonly CILocation[] location;
|
@readonly CILocation[] location;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//called when entity was created
|
||||||
void onAddEntity(EntitiesData data)
|
void onAddEntity(EntitiesData data)
|
||||||
{
|
{
|
||||||
foreach(i;0..data.length)
|
foreach(i;0..data.length)
|
||||||
{
|
{
|
||||||
if(snake.element(data.location[i]).id == EntityID())snake.element(MapElement(MapElement.Type.apple,data.entity[i].id),data.location[i]);
|
if(snake.element(data.location[i]).id == EntityID())snake.element(MapElement(MapElement.Type.apple,data.entity[i].id),data.location[i]);
|
||||||
else launcher.manager.removeEntity(data.entity[i].id);
|
else gEntityManager.removeEntity(data.entity[i].id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//called when entity was removed
|
||||||
void onRemoveEntity(EntitiesData data)
|
void onRemoveEntity(EntitiesData data)
|
||||||
{
|
{
|
||||||
foreach(i;0..data.length)
|
foreach(i;0..data.length)
|
||||||
|
|
@ -272,6 +283,7 @@ struct AppleSystem
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//system is responsible for killing particles when their life drops below 0
|
||||||
struct ParticleSystem
|
struct ParticleSystem
|
||||||
{
|
{
|
||||||
mixin ECS.System!1;
|
mixin ECS.System!1;
|
||||||
|
|
@ -288,11 +300,12 @@ struct ParticleSystem
|
||||||
foreach(i;0..data.length)
|
foreach(i;0..data.length)
|
||||||
{
|
{
|
||||||
data.particle[i].life -= launcher.deltaTime;
|
data.particle[i].life -= launcher.deltaTime;
|
||||||
if(data.particle[i].life < 0)launcher.manager.removeEntity(data.entities[i].id);
|
if(data.particle[i].life < 0)gEntityManager.removeEntity(data.entities[i].id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//system responsible for moving particles
|
||||||
struct ParticleMovementSystem
|
struct ParticleMovementSystem
|
||||||
{
|
{
|
||||||
mixin ECS.System!1;
|
mixin ECS.System!1;
|
||||||
|
|
@ -363,7 +376,6 @@ struct AnimationRenderSystem
|
||||||
draw_data.position = data.location[i];
|
draw_data.position = data.location[i];
|
||||||
draw_data.coords = data.animation[i].frames[cast(int)(data.animation[i].time)];
|
draw_data.coords = data.animation[i].frames[cast(int)(data.animation[i].time)];
|
||||||
launcher.renderer.draw(draw_data);
|
launcher.renderer.draw(draw_data);
|
||||||
//launcher.renderer.draw(snake.texture, cast(vec2)cast(ivec2)data.location[i], vec2(16,16), data.animation[i].frames[cast(int)(data.animation[i].time)], -1, 0x80808080);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -373,8 +385,6 @@ struct MoveSystem
|
||||||
mixin ECS.System!64;
|
mixin ECS.System!64;
|
||||||
|
|
||||||
EntityTemplate* destroy_template;
|
EntityTemplate* destroy_template;
|
||||||
//CLocation* destroy_location;
|
|
||||||
//CParticleVector* destroy_vector;
|
|
||||||
|
|
||||||
struct EntitiesData
|
struct EntitiesData
|
||||||
{
|
{
|
||||||
|
|
@ -387,9 +397,8 @@ struct MoveSystem
|
||||||
|
|
||||||
void setTemplates()
|
void setTemplates()
|
||||||
{
|
{
|
||||||
|
//template is used for adding particles when snake will collide with himself
|
||||||
destroy_template = snake.snake_destroy_particle;
|
destroy_template = snake.snake_destroy_particle;
|
||||||
//destroy_location = destroy_template.getComponent!CLocation;
|
|
||||||
//destroy_vector = destroy_template.getComponent!CParticleVector;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void moveLocation(ref CILocation location, CMovement.Direction direction)
|
void moveLocation(ref CILocation location, CMovement.Direction direction)
|
||||||
|
|
@ -446,7 +455,7 @@ struct MoveSystem
|
||||||
//destroy_location.x = loc.x * 16;
|
//destroy_location.x = loc.x * 16;
|
||||||
//destroy_location.y = loc.y * 16;
|
//destroy_location.y = loc.y * 16;
|
||||||
snake.element(MapElement(MapElement.Type.empty, EntityID()),loc);
|
snake.element(MapElement(MapElement.Type.empty, EntityID()),loc);
|
||||||
launcher.manager.addEntity(snake.snake_destroy_particle,[CLocation(cast(vec2)(loc * 16)).ref_].staticArray);
|
gEntityManager.addEntity(snake.snake_destroy_particle,[CLocation(cast(vec2)(loc * 16)).ref_].staticArray);
|
||||||
|
|
||||||
CLocation destroy_location;
|
CLocation destroy_location;
|
||||||
foreach(j;0..10)
|
foreach(j;0..10)
|
||||||
|
|
@ -455,15 +464,15 @@ struct MoveSystem
|
||||||
destroy_location.y = loc.y * 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);
|
snake.element(MapElement(MapElement.Type.empty, EntityID()),loc);
|
||||||
launcher.manager.addEntity(snake.snake_destroy_particle, [destroy_location.ref_, CParticleVector(vec2(randomf(),randomf())*0.4-0.2).ref_].staticArray);
|
gEntityManager.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.x = new_location.x * 16;
|
||||||
//destroy_location.y = new_location.y * 16;
|
//destroy_location.y = new_location.y * 16;
|
||||||
snake.element(MapElement(MapElement.Type.empty, EntityID()),new_location);
|
snake.element(MapElement(MapElement.Type.empty, EntityID()),new_location);
|
||||||
launcher.manager.addEntity(snake.snake_destroy_particle,[CLocation(cast(vec2)(new_location * 16)).ref_].staticArray);
|
gEntityManager.addEntity(snake.snake_destroy_particle,[CLocation(cast(vec2)(new_location * 16)).ref_].staticArray);
|
||||||
launcher.manager.removeEntity(data.entities[i].id);
|
gEntityManager.removeEntity(data.entities[i].id);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MapElement.Type.wall:break;
|
case MapElement.Type.wall:break;
|
||||||
|
|
@ -482,7 +491,7 @@ struct MoveSystem
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MapElement.Type.apple:
|
case MapElement.Type.apple:
|
||||||
launcher.manager.removeEntity(snake.element(data.location[i].location).id);
|
gEntityManager.removeEntity(snake.element(data.location[i].location).id);
|
||||||
if(data.snakes[i].parts.length >= 99)
|
if(data.snakes[i].parts.length >= 99)
|
||||||
{
|
{
|
||||||
snake.addApple();
|
snake.addApple();
|
||||||
|
|
@ -537,7 +546,7 @@ struct SnakeSystem
|
||||||
foreach(i;0..data.length)
|
foreach(i;0..data.length)
|
||||||
{
|
{
|
||||||
if(snake.element(data.location[i]).id == EntityID())snake.element(MapElement(MapElement.Type.snake,data.entity[i].id),data.location[i]);
|
if(snake.element(data.location[i]).id == EntityID())snake.element(MapElement(MapElement.Type.snake,data.entity[i].id),data.location[i]);
|
||||||
else launcher.manager.removeEntity(data.entity[i].id);
|
else gEntityManager.removeEntity(data.entity[i].id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -814,7 +823,7 @@ struct CleanSystem
|
||||||
{
|
{
|
||||||
foreach(i; 0..data.length)
|
foreach(i; 0..data.length)
|
||||||
{
|
{
|
||||||
launcher.manager.removeEntity(data.entities[i].id);
|
gEntityManager.removeEntity(data.entities[i].id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -859,38 +868,38 @@ void snakeRegister()
|
||||||
snake.texture.create();
|
snake.texture.create();
|
||||||
snake.texture.load("assets/textures/atlas.png");
|
snake.texture.load("assets/textures/atlas.png");
|
||||||
|
|
||||||
launcher.manager.beginRegister();
|
gEntityManager.beginRegister();
|
||||||
|
|
||||||
launcher.manager.registerPass("fixed");
|
gEntityManager.registerPass("fixed");
|
||||||
|
|
||||||
registerRenderingModule(launcher.manager);
|
registerRenderingModule(gEntityManager);
|
||||||
|
|
||||||
launcher.manager.registerComponent!CLocation;
|
gEntityManager.registerComponent!CLocation;
|
||||||
launcher.manager.registerComponent!CILocation;
|
gEntityManager.registerComponent!CILocation;
|
||||||
launcher.manager.registerComponent!CSnake;
|
gEntityManager.registerComponent!CSnake;
|
||||||
launcher.manager.registerComponent!CApple;
|
gEntityManager.registerComponent!CApple;
|
||||||
launcher.manager.registerComponent!CParticle;
|
gEntityManager.registerComponent!CParticle;
|
||||||
launcher.manager.registerComponent!CParticleVector;
|
gEntityManager.registerComponent!CParticleVector;
|
||||||
launcher.manager.registerComponent!CMovement;
|
gEntityManager.registerComponent!CMovement;
|
||||||
launcher.manager.registerComponent!CInput;
|
gEntityManager.registerComponent!CInput;
|
||||||
launcher.manager.registerComponent!CAnimation;
|
gEntityManager.registerComponent!CAnimation;
|
||||||
|
|
||||||
launcher.manager.registerSystem!MoveSystem(0,"fixed");
|
gEntityManager.registerSystem!MoveSystem(0,"fixed");
|
||||||
launcher.manager.registerSystem!InputSystem(-100);
|
gEntityManager.registerSystem!InputSystem(-100);
|
||||||
launcher.manager.registerSystem!FixSnakeDirectionSystem(-1,"fixed");
|
gEntityManager.registerSystem!FixSnakeDirectionSystem(-1,"fixed");
|
||||||
launcher.manager.registerSystem!AnimationRenderSystem(100);
|
gEntityManager.registerSystem!AnimationRenderSystem(100);
|
||||||
launcher.manager.registerSystem!AnimationSystem(-1);
|
gEntityManager.registerSystem!AnimationSystem(-1);
|
||||||
launcher.manager.registerSystem!ParticleSystem(-1);
|
gEntityManager.registerSystem!ParticleSystem(-1);
|
||||||
launcher.manager.registerSystem!ParticleMovementSystem(-1);
|
gEntityManager.registerSystem!ParticleMovementSystem(-1);
|
||||||
launcher.manager.registerSystem!DrawAppleSystem(99);
|
gEntityManager.registerSystem!DrawAppleSystem(99);
|
||||||
launcher.manager.registerSystem!DrawSnakeSystem(101);
|
gEntityManager.registerSystem!DrawSnakeSystem(101);
|
||||||
|
|
||||||
launcher.manager.registerSystem!CopyLocationSystem(100);
|
gEntityManager.registerSystem!CopyLocationSystem(100);
|
||||||
//launcher.manager.registerSystem!AppleRemoveSystem(100);
|
//gEntityManager.registerSystem!AppleRemoveSystem(100);
|
||||||
launcher.manager.registerSystem!AppleSystem(101);
|
gEntityManager.registerSystem!AppleSystem(101);
|
||||||
launcher.manager.registerSystem!SnakeSystem(101);
|
gEntityManager.registerSystem!SnakeSystem(101);
|
||||||
|
|
||||||
launcher.manager.endRegister();
|
gEntityManager.endRegister();
|
||||||
}
|
}
|
||||||
|
|
||||||
void snakeStart()
|
void snakeStart()
|
||||||
|
|
@ -918,12 +927,12 @@ void snakeStart()
|
||||||
|
|
||||||
{
|
{
|
||||||
ushort[5] components = [becsID!CILocation, becsID!CSnake, becsID!CMovement, becsID!CInput, becsID!CLocation];
|
ushort[5] components = [becsID!CILocation, becsID!CSnake, becsID!CMovement, becsID!CInput, becsID!CLocation];
|
||||||
snake.snake_tmpl = launcher.manager.allocateTemplate(components);
|
snake.snake_tmpl = gEntityManager.allocateTemplate(components);
|
||||||
launcher.manager.addEntity(snake.snake_tmpl,[CILocation(ivec2(2,2)).ref_].staticArray);
|
gEntityManager.addEntity(snake.snake_tmpl,[CILocation(ivec2(2,2)).ref_].staticArray);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
snake.snake_destroy_particle = launcher.manager.allocateTemplate([becsID!CLocation, becsID!CParticle, becsID!CParticleVector, becsID!CAnimation, becsID!CLocation].staticArray);
|
snake.snake_destroy_particle = gEntityManager.allocateTemplate([becsID!CLocation, becsID!CParticle, becsID!CParticleVector, becsID!CAnimation, becsID!CLocation].staticArray);
|
||||||
CAnimation* canim = snake.snake_destroy_particle.getComponent!CAnimation;
|
CAnimation* canim = snake.snake_destroy_particle.getComponent!CAnimation;
|
||||||
canim.frames = snake.snake_destroy_particle_frames;
|
canim.frames = snake.snake_destroy_particle_frames;
|
||||||
CParticle* particle = snake.snake_destroy_particle.getComponent!CParticle;
|
CParticle* particle = snake.snake_destroy_particle.getComponent!CParticle;
|
||||||
|
|
@ -932,21 +941,21 @@ void snakeStart()
|
||||||
|
|
||||||
{
|
{
|
||||||
ushort[3] components = [becsID!CILocation, becsID!CApple, becsID!CLocation];
|
ushort[3] components = [becsID!CILocation, becsID!CApple, becsID!CLocation];
|
||||||
snake.apple_tmpl = launcher.manager.allocateTemplate(components);
|
snake.apple_tmpl = gEntityManager.allocateTemplate(components);
|
||||||
snake.addApple();
|
snake.addApple();
|
||||||
}
|
}
|
||||||
|
|
||||||
launcher.gui_manager.addTemplate(launcher.manager.allocateTemplate(snake.snake_tmpl), "Snake");
|
launcher.gui_manager.addTemplate(gEntityManager.allocateTemplate(snake.snake_tmpl), "Snake");
|
||||||
launcher.gui_manager.addTemplate(launcher.manager.allocateTemplate(snake.apple_tmpl), "Apple");
|
launcher.gui_manager.addTemplate(gEntityManager.allocateTemplate(snake.apple_tmpl), "Apple");
|
||||||
launcher.gui_manager.addTemplate(launcher.manager.allocateTemplate(snake.snake_destroy_particle), "Particle");
|
launcher.gui_manager.addTemplate(gEntityManager.allocateTemplate(snake.snake_destroy_particle), "Particle");
|
||||||
|
|
||||||
MoveSystem* move_system = launcher.manager.getSystem!MoveSystem();
|
MoveSystem* move_system = gEntityManager.getSystem!MoveSystem();
|
||||||
move_system.setTemplates();
|
move_system.setTemplates();
|
||||||
}
|
}
|
||||||
|
|
||||||
void snakeEnd()
|
void snakeEnd()
|
||||||
{
|
{
|
||||||
//launcher.manager.freeTemplate(simple.tmpl);
|
//gEntityManager.freeTemplate(simple.tmpl);
|
||||||
Mallocator.dispose(snake);
|
Mallocator.dispose(snake);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -970,7 +979,7 @@ bool snakeLoop()
|
||||||
// igEnd();
|
// igEnd();
|
||||||
// }
|
// }
|
||||||
|
|
||||||
launcher.manager.begin();
|
gEntityManager.begin();
|
||||||
|
|
||||||
float delta_time = launcher.deltaTime;
|
float delta_time = launcher.deltaTime;
|
||||||
if(delta_time > 2000)delta_time = 2000;
|
if(delta_time > 2000)delta_time = 2000;
|
||||||
|
|
@ -983,12 +992,12 @@ bool snakeLoop()
|
||||||
{
|
{
|
||||||
time -= 200;
|
time -= 200;
|
||||||
|
|
||||||
launcher.manager.update("fixed");
|
gEntityManager.update("fixed");
|
||||||
}
|
}
|
||||||
|
|
||||||
launcher.manager.update();
|
gEntityManager.update();
|
||||||
|
|
||||||
launcher.manager.end();
|
gEntityManager.end();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,11 +20,6 @@ import game_core.basic;
|
||||||
import game_core.rendering;
|
import game_core.rendering;
|
||||||
import game_core.collision;
|
import game_core.collision;
|
||||||
|
|
||||||
//import std.math : PI;
|
|
||||||
|
|
||||||
|
|
||||||
//import std.array : staticArray;
|
|
||||||
|
|
||||||
private enum float px = 1.0/512.0;
|
private enum float px = 1.0/512.0;
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -59,12 +54,12 @@ You can add any component to any entity which sometimes can give fun results. Th
|
||||||
~this() @nogc nothrow
|
~this() @nogc nothrow
|
||||||
{
|
{
|
||||||
// if(shoot_grid)Mallocator.dispose(shoot_grid);
|
// if(shoot_grid)Mallocator.dispose(shoot_grid);
|
||||||
if(enemy_tmpl)launcher.manager.freeTemplate(enemy_tmpl);
|
if(enemy_tmpl)gEntityManager.freeTemplate(enemy_tmpl);
|
||||||
if(ship_tmpl)launcher.manager.freeTemplate(ship_tmpl);
|
if(ship_tmpl)gEntityManager.freeTemplate(ship_tmpl);
|
||||||
if(laser_tmpl)launcher.manager.freeTemplate(laser_tmpl);
|
if(laser_tmpl)gEntityManager.freeTemplate(laser_tmpl);
|
||||||
foreach (EntityTemplate* tmpl; bullet_tmpl)
|
foreach (EntityTemplate* tmpl; bullet_tmpl)
|
||||||
{
|
{
|
||||||
if(tmpl)launcher.manager.freeTemplate(tmpl);
|
if(tmpl)gEntityManager.freeTemplate(tmpl);
|
||||||
}
|
}
|
||||||
texture.destroy();
|
texture.destroy();
|
||||||
}
|
}
|
||||||
|
|
@ -503,7 +498,7 @@ struct ParentOwnerSystem
|
||||||
//currently EntitiesData always has only one element
|
//currently EntitiesData always has only one element
|
||||||
foreach(child; data.children[0].childern)
|
foreach(child; data.children[0].childern)
|
||||||
{
|
{
|
||||||
launcher.manager.removeEntity(child);
|
gEntityManager.removeEntity(child);
|
||||||
}
|
}
|
||||||
if(data.children[0].childern.length)Mallocator.dispose(data.children[0].childern);
|
if(data.children[0].childern.length)Mallocator.dispose(data.children[0].childern);
|
||||||
}
|
}
|
||||||
|
|
@ -536,28 +531,28 @@ struct ShipWeaponSystem
|
||||||
laser1_tmpl.getComponent!CTargetParent().parent = entity.id;
|
laser1_tmpl.getComponent!CTargetParent().parent = entity.id;
|
||||||
laser2_tmpl.getComponent!CTargetParent().parent = entity.id;
|
laser2_tmpl.getComponent!CTargetParent().parent = entity.id;
|
||||||
main_weapon_tmpl.getComponent!CTargetParent().parent = entity.id;
|
main_weapon_tmpl.getComponent!CTargetParent().parent = entity.id;
|
||||||
weapons[0] = launcher.manager.addEntity(laser1_tmpl).id;
|
weapons[0] = gEntityManager.addEntity(laser1_tmpl).id;
|
||||||
weapons[1] = launcher.manager.addEntity(laser2_tmpl).id;
|
weapons[1] = gEntityManager.addEntity(laser2_tmpl).id;
|
||||||
weapons[2] = launcher.manager.addEntity(main_weapon_tmpl).id;
|
weapons[2] = gEntityManager.addEntity(main_weapon_tmpl).id;
|
||||||
children.childern = Mallocator.makeArray(weapons);
|
children.childern = Mallocator.makeArray(weapons);
|
||||||
}
|
}
|
||||||
|
|
||||||
void create()
|
void create()
|
||||||
{
|
{
|
||||||
laser1_tmpl = launcher.manager.allocateTemplate([becsID!CWeapon, becsID!CLocation, becsID!CShootDirection, becsID!CTargetParent, becsID!CGuild, becsID!CVelocity].staticArray);
|
laser1_tmpl = gEntityManager.allocateTemplate([becsID!CWeapon, becsID!CLocation, becsID!CShootDirection, becsID!CTargetParent, becsID!CGuild, becsID!CVelocity].staticArray);
|
||||||
main_weapon_tmpl = launcher.manager.allocateTemplate([becsID!CLocation, becsID!CShootDirection, becsID!CTargetParent, becsID!CGuild, becsID!CVelocity].staticArray);
|
main_weapon_tmpl = gEntityManager.allocateTemplate([becsID!CLocation, becsID!CShootDirection, becsID!CTargetParent, becsID!CGuild, becsID!CVelocity].staticArray);
|
||||||
*laser1_tmpl.getComponent!CWeapon = CWeapon(0,CWeapon.Type.laser,3);
|
*laser1_tmpl.getComponent!CWeapon = CWeapon(0,CWeapon.Type.laser,3);
|
||||||
laser1_tmpl.getComponent!CTargetParent().rel_pos = vec2(10,13);
|
laser1_tmpl.getComponent!CTargetParent().rel_pos = vec2(10,13);
|
||||||
main_weapon_tmpl.getComponent!CTargetParent().rel_pos = vec2(0,4);
|
main_weapon_tmpl.getComponent!CTargetParent().rel_pos = vec2(0,4);
|
||||||
laser2_tmpl = launcher.manager.allocateTemplate(laser1_tmpl);
|
laser2_tmpl = gEntityManager.allocateTemplate(laser1_tmpl);
|
||||||
laser2_tmpl.getComponent!CTargetParent().rel_pos = vec2(-10,13);
|
laser2_tmpl.getComponent!CTargetParent().rel_pos = vec2(-10,13);
|
||||||
}
|
}
|
||||||
|
|
||||||
~this()
|
~this()
|
||||||
{
|
{
|
||||||
launcher.manager.freeTemplate(laser1_tmpl);
|
gEntityManager.freeTemplate(laser1_tmpl);
|
||||||
launcher.manager.freeTemplate(laser2_tmpl);
|
gEntityManager.freeTemplate(laser2_tmpl);
|
||||||
launcher.manager.freeTemplate(main_weapon_tmpl);
|
gEntityManager.freeTemplate(main_weapon_tmpl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -579,14 +574,14 @@ struct ShipWeaponSystem
|
||||||
if(depth)top_tmpl.getComponent!CDepth().value = cast(short)(depth.value - 2);
|
if(depth)top_tmpl.getComponent!CDepth().value = cast(short)(depth.value - 2);
|
||||||
else top_tmpl.getComponent!CDepth().value = -2;
|
else top_tmpl.getComponent!CDepth().value = -2;
|
||||||
|
|
||||||
weapons[0] = launcher.manager.addEntity(weapon_tmpl).id;
|
weapons[0] = gEntityManager.addEntity(weapon_tmpl).id;
|
||||||
weapons[1] = launcher.manager.addEntity(top_tmpl).id;
|
weapons[1] = gEntityManager.addEntity(top_tmpl).id;
|
||||||
children.childern = Mallocator.makeArray(weapons);
|
children.childern = Mallocator.makeArray(weapons);
|
||||||
}
|
}
|
||||||
|
|
||||||
void create()
|
void create()
|
||||||
{
|
{
|
||||||
weapon_tmpl = launcher.manager.allocateTemplate(
|
weapon_tmpl = gEntityManager.allocateTemplate(
|
||||||
[becsID!CWeapon, becsID!CLocation, becsID!CShootDirection,
|
[becsID!CWeapon, becsID!CLocation, becsID!CShootDirection,
|
||||||
becsID!CTargetParent, becsID!CGuild, becsID!CVelocity,
|
becsID!CTargetParent, becsID!CGuild, becsID!CVelocity,
|
||||||
becsID!CAutoShoot, becsID!CTarget, becsID!CTargetPlayerShip,
|
becsID!CAutoShoot, becsID!CTarget, becsID!CTargetPlayerShip,
|
||||||
|
|
@ -602,7 +597,7 @@ struct ShipWeaponSystem
|
||||||
weapon_tmpl.getComponent!CTexCoords().value = 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 = gEntityManager.allocateTemplate(
|
||||||
[becsID!CLocation, becsID!CTargetParent, becsID!CScale,
|
[becsID!CLocation, becsID!CTargetParent, becsID!CScale,
|
||||||
becsID!CTexCoords, becsID!CDepth].staticArray);
|
becsID!CTexCoords, becsID!CDepth].staticArray);
|
||||||
top_tmpl.getComponent!CTargetParent().rel_pos = vec2(0,1);
|
top_tmpl.getComponent!CTargetParent().rel_pos = vec2(0,1);
|
||||||
|
|
@ -614,8 +609,8 @@ struct ShipWeaponSystem
|
||||||
|
|
||||||
~this()
|
~this()
|
||||||
{
|
{
|
||||||
launcher.manager.freeTemplate(weapon_tmpl);
|
gEntityManager.freeTemplate(weapon_tmpl);
|
||||||
launcher.manager.freeTemplate(top_tmpl);
|
gEntityManager.freeTemplate(top_tmpl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -637,16 +632,16 @@ struct ShipWeaponSystem
|
||||||
tower2_tmpl.getComponent!CTargetParent().parent = entity.id;
|
tower2_tmpl.getComponent!CTargetParent().parent = entity.id;
|
||||||
tower3_tmpl.getComponent!CTargetParent().parent = entity.id;
|
tower3_tmpl.getComponent!CTargetParent().parent = entity.id;
|
||||||
tower4_tmpl.getComponent!CTargetParent().parent = entity.id;
|
tower4_tmpl.getComponent!CTargetParent().parent = entity.id;
|
||||||
towers[0] = launcher.manager.addEntity(tower1_tmpl).id;
|
towers[0] = gEntityManager.addEntity(tower1_tmpl).id;
|
||||||
towers[1] = launcher.manager.addEntity(tower2_tmpl).id;
|
towers[1] = gEntityManager.addEntity(tower2_tmpl).id;
|
||||||
towers[2] = launcher.manager.addEntity(tower3_tmpl).id;
|
towers[2] = gEntityManager.addEntity(tower3_tmpl).id;
|
||||||
towers[3] = launcher.manager.addEntity(tower4_tmpl).id;
|
towers[3] = gEntityManager.addEntity(tower4_tmpl).id;
|
||||||
children.childern = Mallocator.makeArray(towers);
|
children.childern = Mallocator.makeArray(towers);
|
||||||
}
|
}
|
||||||
|
|
||||||
void create()
|
void create()
|
||||||
{
|
{
|
||||||
tower1_tmpl = launcher.manager.allocateTemplate(
|
tower1_tmpl = gEntityManager.allocateTemplate(
|
||||||
[becsID!CColor, becsID!CHitMark, becsID!CHitPoints, becsID!CLocation,
|
[becsID!CColor, becsID!CHitMark, becsID!CHitPoints, becsID!CLocation,
|
||||||
becsID!CTexCoords, becsID!CScale, becsID!CEnemy,
|
becsID!CTexCoords, becsID!CScale, becsID!CEnemy,
|
||||||
becsID!CShootGrid, becsID!CGuild, becsID!CInit,
|
becsID!CShootGrid, becsID!CGuild, becsID!CInit,
|
||||||
|
|
@ -654,11 +649,6 @@ struct ShipWeaponSystem
|
||||||
becsID!CSpawnUponDeath, becsID!CShootWaveUponDeath, becsID!CShootGridMask].staticArray
|
becsID!CSpawnUponDeath, becsID!CShootWaveUponDeath, becsID!CShootGridMask].staticArray
|
||||||
);
|
);
|
||||||
|
|
||||||
/*CTexCoords* tex_comp = tower1_tmpl.getComponent!CTexCoords;
|
|
||||||
//tex_comp.tex = space_invaders.texture;//ship_tex;
|
|
||||||
tex_comp.coords = vec4(96*px,96*px,16*px,16*px);
|
|
||||||
CLocation* loc_comp = tower1_tmpl.getComponent!CLocation;
|
|
||||||
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!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!CLocation().value = vec2(64,space_invaders.map_size.y - 16);
|
||||||
tower1_tmpl.getComponent!CGuild().guild = 1;
|
tower1_tmpl.getComponent!CGuild().guild = 1;
|
||||||
|
|
@ -668,24 +658,24 @@ struct ShipWeaponSystem
|
||||||
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);
|
||||||
|
|
||||||
tower2_tmpl = launcher.manager.allocateTemplate(tower1_tmpl);
|
tower2_tmpl = gEntityManager.allocateTemplate(tower1_tmpl);
|
||||||
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 = gEntityManager.allocateTemplate(tower1_tmpl);
|
||||||
tower3_tmpl.getComponent!CDepth().value = 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 = gEntityManager.allocateTemplate(tower1_tmpl);
|
||||||
tower4_tmpl.getComponent!CDepth().value = 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
~this()
|
~this()
|
||||||
{
|
{
|
||||||
launcher.manager.freeTemplate(tower1_tmpl);
|
gEntityManager.freeTemplate(tower1_tmpl);
|
||||||
launcher.manager.freeTemplate(tower2_tmpl);
|
gEntityManager.freeTemplate(tower2_tmpl);
|
||||||
launcher.manager.freeTemplate(tower3_tmpl);
|
gEntityManager.freeTemplate(tower3_tmpl);
|
||||||
launcher.manager.freeTemplate(tower4_tmpl);
|
gEntityManager.freeTemplate(tower4_tmpl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -698,21 +688,11 @@ struct ShipWeaponSystem
|
||||||
ship.create();
|
ship.create();
|
||||||
tower.create();
|
tower.create();
|
||||||
boss.create();
|
boss.create();
|
||||||
/*ship.laser1_tmpl = launcher.manager.allocateTemplate([becsID!CWeapon, becsID!CLocation, becsID!CShootDirection, becsID!CTargetParent, becsID!CGuild, becsID!CVelocity].staticArray);
|
|
||||||
ship.main_weapon_tmpl = launcher.manager.allocateTemplate([becsID!CLocation, becsID!CShootDirection, becsID!CTargetParent, becsID!CGuild, becsID!CVelocity].staticArray);
|
|
||||||
*ship.laser1_tmpl.getComponent!CWeapon = CWeapon(3,0.0);
|
|
||||||
ship.laser1_tmpl.getComponent!CTargetParent().rel_pos = vec2(10,13);
|
|
||||||
ship.main_weapon_tmpl.getComponent!CTargetParent().rel_pos = vec2(0,4);
|
|
||||||
ship.laser2_tmpl = launcher.manager.allocateTemplate(ship.laser1_tmpl);
|
|
||||||
ship.laser2_tmpl.getComponent!CTargetParent().rel_pos = vec2(-10,13);*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void onDestroy()
|
void onDestroy()
|
||||||
{
|
{
|
||||||
__xdtor();
|
__xdtor();
|
||||||
/*launcher.manager.freeTemplate(laser1_tmpl);
|
|
||||||
launcher.manager.freeTemplate(laser2_tmpl);
|
|
||||||
launcher.manager.freeTemplate(main_weapon_tmpl);*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void onAddEntity(EntitiesData data)
|
void onAddEntity(EntitiesData data)
|
||||||
|
|
@ -747,7 +727,7 @@ struct MoveToParentTargetSystem
|
||||||
{
|
{
|
||||||
foreach(i;0..data.length)
|
foreach(i;0..data.length)
|
||||||
{
|
{
|
||||||
Entity* target = launcher.manager.getEntity(data.target[i].parent);
|
Entity* target = gEntityManager.getEntity(data.target[i].parent);
|
||||||
if(target)
|
if(target)
|
||||||
{
|
{
|
||||||
CLocation* target_loc = target.getComponent!CLocation;
|
CLocation* target_loc = target.getComponent!CLocation;
|
||||||
|
|
@ -766,7 +746,7 @@ struct MoveToParentTargetSystem
|
||||||
else
|
else
|
||||||
foreach(i;0..data.length)
|
foreach(i;0..data.length)
|
||||||
{
|
{
|
||||||
Entity* target = launcher.manager.getEntity(data.target[i].parent);
|
Entity* target = gEntityManager.getEntity(data.target[i].parent);
|
||||||
if(target)
|
if(target)
|
||||||
{
|
{
|
||||||
CLocation* target_loc = target.getComponent!CLocation;
|
CLocation* target_loc = target.getComponent!CLocation;
|
||||||
|
|
@ -951,34 +931,12 @@ struct ShootingSystem
|
||||||
@optional @readonly CRotation[] rotation;
|
@optional @readonly CRotation[] rotation;
|
||||||
}
|
}
|
||||||
|
|
||||||
//EntityTemplate* laser_tmpl;
|
|
||||||
EntityTemplate* fire_tmpl;
|
EntityTemplate* fire_tmpl;
|
||||||
|
|
||||||
//EntityTemplate*[5] bullet_tmpl;
|
|
||||||
|
|
||||||
///Called inside "registerSystem" function
|
///Called inside "registerSystem" function
|
||||||
void onCreate()
|
void onCreate()
|
||||||
{
|
{
|
||||||
/*bullet_tmpl[0] = launcher.manager.allocateTemplate(
|
fire_tmpl = gEntityManager.allocateTemplate(
|
||||||
[becsID!CLocation, becsID!CTexCoords, becsID!CVelocity,
|
|
||||||
becsID!CScale, becsID!CBullet, becsID!CGuild].staticArray
|
|
||||||
);
|
|
||||||
bullet_tmpl[0].getComponent!CTexCoords().value = vec4(0,24,2,8)*px;
|
|
||||||
bullet_tmpl[0].getComponent!CScale().value = vec2(2,8);
|
|
||||||
|
|
||||||
bullet_tmpl[1] = launcher.manager.allocateTemplate(bullet_tmpl[0]);
|
|
||||||
bullet_tmpl[2] = launcher.manager.allocateTemplate(bullet_tmpl[0]);
|
|
||||||
bullet_tmpl[2].getComponent!CTexCoords().value = 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!CTexCoords().value = vec4(56,32,2,2)*px;
|
|
||||||
bullet_tmpl[3].getComponent!CScale().value = vec2(2,2);
|
|
||||||
// bullet_tmpl[3].getComponent!CTexCoords().value = vec4(48,32,8,8)*px;
|
|
||||||
// bullet_tmpl[3].getComponent!CScale().value = vec2(8,8);
|
|
||||||
bullet_tmpl[4] = launcher.manager.allocateTemplate(bullet_tmpl[0]);*/
|
|
||||||
|
|
||||||
|
|
||||||
fire_tmpl = launcher.manager.allocateTemplate(
|
|
||||||
[becsID!CLocation, becsID!CTexCoords, becsID!CScale,
|
[becsID!CLocation, becsID!CTexCoords, becsID!CScale,
|
||||||
becsID!CAnimation, becsID!CParticle, becsID!CRotation,
|
becsID!CAnimation, becsID!CParticle, becsID!CRotation,
|
||||||
becsID!CVelocity, becsID!CDamping].staticArray
|
becsID!CVelocity, becsID!CDamping].staticArray
|
||||||
|
|
@ -992,19 +950,11 @@ struct ShootingSystem
|
||||||
|
|
||||||
void onDestroy()
|
void onDestroy()
|
||||||
{
|
{
|
||||||
//launcher.manager.freeTemplate(laser_tmpl);
|
gEntityManager.freeTemplate(fire_tmpl);
|
||||||
/*foreach (EntityTemplate* tmpl; bullet_tmpl)
|
|
||||||
{
|
|
||||||
launcher.manager.freeTemplate(tmpl);
|
|
||||||
}*/
|
|
||||||
launcher.manager.freeTemplate(fire_tmpl);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool onBegin()
|
bool onBegin()
|
||||||
{
|
{
|
||||||
/*laser_location = space_invaders.laser_tmpl.getComponent!CLocation;
|
|
||||||
laser_velocity = space_invaders.laser_tmpl.getComponent!CVelocity;
|
|
||||||
laser_guild = space_invaders.laser_tmpl.getComponent!CGuild;*/
|
|
||||||
if(launcher.getKeyState(SDL_SCANCODE_SPACE))
|
if(launcher.getKeyState(SDL_SCANCODE_SPACE))
|
||||||
{
|
{
|
||||||
shoot = true;
|
shoot = true;
|
||||||
|
|
@ -1081,8 +1031,8 @@ struct ShootingSystem
|
||||||
fire_location.value += data.weapon_location[i].rel_pos;
|
fire_location.value += data.weapon_location[i].rel_pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
launcher.manager.addEntity(space_invaders.bullet_tmpl[data.laser[i].type],[laser_velocity.ref_, laser_guild.ref_, laser_location.ref_].staticArray);
|
gEntityManager.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);
|
gEntityManager.addEntity(fire_tmpl,[fire_location.ref_, fire_rotation.ref_, fire_velocity.ref_].staticArray);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1122,8 +1072,8 @@ struct BulletsCollisionSystem
|
||||||
{
|
{
|
||||||
if(space_invaders.shoot_grid.test(id, data.location[i], cast(ubyte)(~(1 << data.guild[i].guild))))
|
if(space_invaders.shoot_grid.test(id, data.location[i], cast(ubyte)(~(1 << data.guild[i].guild))))
|
||||||
{
|
{
|
||||||
launcher.manager.sendEvent(id, EBulletHit(data.entity[i].id,data.bullet[i].damage));
|
gEntityManager.sendEvent(id, EBulletHit(data.entity[i].id,data.bullet[i].damage));
|
||||||
//launcher.manager.removeEntity(data.entity[i].id);
|
//gEntityManager.removeEntity(data.entity[i].id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1175,7 +1125,7 @@ struct ParticleEmittingSystem
|
||||||
|
|
||||||
void onCreate()
|
void onCreate()
|
||||||
{
|
{
|
||||||
templates[0] = launcher.manager.allocateTemplate(
|
templates[0] = gEntityManager.allocateTemplate(
|
||||||
[becsID!CLocation, becsID!CTexCoords, becsID!CScale,
|
[becsID!CLocation, becsID!CTexCoords, becsID!CScale,
|
||||||
becsID!CAnimation, becsID!CParticle, becsID!CRotation,
|
becsID!CAnimation, becsID!CParticle, becsID!CRotation,
|
||||||
becsID!CVelocity, becsID!CDamping, becsID!CDepth].staticArray);
|
becsID!CVelocity, becsID!CDamping, becsID!CDepth].staticArray);
|
||||||
|
|
@ -1188,7 +1138,7 @@ struct ParticleEmittingSystem
|
||||||
{
|
{
|
||||||
foreach(tmpl; templates)
|
foreach(tmpl; templates)
|
||||||
{
|
{
|
||||||
launcher.manager.freeTemplate(tmpl);
|
gEntityManager.freeTemplate(tmpl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1215,7 +1165,7 @@ struct ParticleEmittingSystem
|
||||||
depth.value = data.depth[i];
|
depth.value = data.depth[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
launcher.manager.addEntity(templates[0],[data.location[i].ref_,velocity.ref_,depth.ref_].staticArray);
|
gEntityManager.addEntity(templates[0],[data.location[i].ref_,velocity.ref_,depth.ref_].staticArray);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1243,11 +1193,11 @@ struct UpgradeCollisionSystem
|
||||||
{
|
{
|
||||||
if(space_invaders.shoot_grid.test(id, data.location[i], cast(ubyte)(0xFF)))
|
if(space_invaders.shoot_grid.test(id, data.location[i], cast(ubyte)(0xFF)))
|
||||||
{
|
{
|
||||||
Entity* entity = launcher.manager.getEntity(id);
|
Entity* entity = gEntityManager.getEntity(id);
|
||||||
if(entity && entity.hasComponent(becsID!CShip))
|
if(entity && entity.hasComponent(becsID!CShip))
|
||||||
{
|
{
|
||||||
launcher.manager.sendEvent(id, EUpgrade());
|
gEntityManager.sendEvent(id, EUpgrade());
|
||||||
launcher.manager.removeEntity(data.entity[i].id);
|
gEntityManager.removeEntity(data.entity[i].id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1279,7 +1229,7 @@ struct UpgradeSystem
|
||||||
{
|
{
|
||||||
foreach(child;children.childern)
|
foreach(child;children.childern)
|
||||||
{
|
{
|
||||||
launcher.manager.sendEvent(child,EUpgrade());
|
gEntityManager.sendEvent(child,EUpgrade());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1472,7 +1422,7 @@ struct HitPointsSystem
|
||||||
|
|
||||||
void onCreate()
|
void onCreate()
|
||||||
{
|
{
|
||||||
upgrade_tmpl = launcher.manager.allocateTemplate(
|
upgrade_tmpl = gEntityManager.allocateTemplate(
|
||||||
[becsID!CVelocity, becsID!CLocation, becsID!CTexCoords,
|
[becsID!CVelocity, becsID!CLocation, becsID!CTexCoords,
|
||||||
becsID!CScale, becsID!CUpgrade, becsID!CAnimation,
|
becsID!CScale, becsID!CUpgrade, becsID!CAnimation,
|
||||||
becsID!CAnimationLooped].staticArray);
|
becsID!CAnimationLooped].staticArray);
|
||||||
|
|
@ -1481,7 +1431,7 @@ struct HitPointsSystem
|
||||||
*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.05);
|
upgrade_tmpl.getComponent!CVelocity().value = vec2(0,-0.05);
|
||||||
|
|
||||||
explosion_tmpl = launcher.manager.allocateTemplate(
|
explosion_tmpl = gEntityManager.allocateTemplate(
|
||||||
[becsID!CDepth, becsID!CParticle, becsID!CLocation,
|
[becsID!CDepth, becsID!CParticle, becsID!CLocation,
|
||||||
becsID!CTexCoords, becsID!CScale, becsID!CAnimation].staticArray);
|
becsID!CTexCoords, becsID!CScale, becsID!CAnimation].staticArray);
|
||||||
//explosion_tmpl.getComponent!(CTexCoords).tex = space_invaders.texture;
|
//explosion_tmpl.getComponent!(CTexCoords).tex = space_invaders.texture;
|
||||||
|
|
@ -1492,8 +1442,8 @@ struct HitPointsSystem
|
||||||
|
|
||||||
void onDestroy()
|
void onDestroy()
|
||||||
{
|
{
|
||||||
launcher.manager.freeTemplate(upgrade_tmpl);
|
gEntityManager.freeTemplate(upgrade_tmpl);
|
||||||
launcher.manager.freeTemplate(explosion_tmpl);
|
gEntityManager.freeTemplate(explosion_tmpl);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*void handleEvent(Entity* entity, EDamage event)
|
/*void handleEvent(Entity* entity, EDamage event)
|
||||||
|
|
@ -1503,8 +1453,8 @@ struct HitPointsSystem
|
||||||
*hp -= event.damage;
|
*hp -= event.damage;
|
||||||
if(*hp <= 0)
|
if(*hp <= 0)
|
||||||
{
|
{
|
||||||
launcher.manager.sendEvent(entity.id, EDeath());
|
gEntityManager.sendEvent(entity.id, EDeath());
|
||||||
//launcher.manager.removeEntity(entity.id);
|
//gEntityManager.removeEntity(entity.id);
|
||||||
}
|
}
|
||||||
CHitMark* hit_mark = entity.getComponent!CHitMark;
|
CHitMark* hit_mark = entity.getComponent!CHitMark;
|
||||||
if(hit_mark)hit_mark.value = 127;
|
if(hit_mark)hit_mark.value = 127;
|
||||||
|
|
@ -1514,12 +1464,12 @@ struct HitPointsSystem
|
||||||
{
|
{
|
||||||
CHitPoints* hp = entity.getComponent!CHitPoints;
|
CHitPoints* hp = entity.getComponent!CHitPoints;
|
||||||
if(*hp <= 0)return;
|
if(*hp <= 0)return;
|
||||||
launcher.manager.removeEntity(event.id);
|
gEntityManager.removeEntity(event.id);
|
||||||
*hp -= event.damage;
|
*hp -= event.damage;
|
||||||
if(*hp <= 0)
|
if(*hp <= 0)
|
||||||
{
|
{
|
||||||
launcher.manager.sendEvent(entity.id, EDeath());
|
gEntityManager.sendEvent(entity.id, EDeath());
|
||||||
//launcher.manager.removeEntity(entity.id);
|
//gEntityManager.removeEntity(entity.id);
|
||||||
}
|
}
|
||||||
CHitMark* hit_mark = entity.getComponent!CHitMark;
|
CHitMark* hit_mark = entity.getComponent!CHitMark;
|
||||||
if(hit_mark)hit_mark.value = 127;
|
if(hit_mark)hit_mark.value = 127;
|
||||||
|
|
@ -1535,12 +1485,12 @@ struct HitPointsSystem
|
||||||
{
|
{
|
||||||
if(randomRange(0, 1000) < 5)
|
if(randomRange(0, 1000) < 5)
|
||||||
{
|
{
|
||||||
launcher.manager.addEntity(upgrade_tmpl,[location.ref_].staticArray);
|
gEntityManager.addEntity(upgrade_tmpl,[location.ref_].staticArray);
|
||||||
}
|
}
|
||||||
launcher.manager.addEntity(explosion_tmpl,[location.ref_].staticArray);
|
gEntityManager.addEntity(explosion_tmpl,[location.ref_].staticArray);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
launcher.manager.removeEntity(entity.id);
|
gEntityManager.removeEntity(entity.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1558,7 +1508,7 @@ struct ChildDestroySystem
|
||||||
CTargetParent* parent = entity.getComponent!CTargetParent;
|
CTargetParent* parent = entity.getComponent!CTargetParent;
|
||||||
if(parent)
|
if(parent)
|
||||||
{
|
{
|
||||||
launcher.manager.sendEvent(parent.parent, EDestroyedChild(entity.id));
|
gEntityManager.sendEvent(parent.parent, EDestroyedChild(entity.id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1603,12 +1553,12 @@ struct ShootWaveSystem
|
||||||
EntityTemplate* tmpl = space_invaders.bullet_tmpl[wave.bullet_type];
|
EntityTemplate* tmpl = space_invaders.bullet_tmpl[wave.bullet_type];
|
||||||
foreach(dir;dirs)
|
foreach(dir;dirs)
|
||||||
{
|
{
|
||||||
if(guild)launcher.manager.addEntity(tmpl,[location.ref_,guild.ref_,CVelocity(dir).ref_].staticArray);
|
if(guild)gEntityManager.addEntity(tmpl,[location.ref_,guild.ref_,CVelocity(dir).ref_].staticArray);
|
||||||
else launcher.manager.addEntity(tmpl,[location.ref_,CVelocity(dir).ref_].staticArray);
|
else gEntityManager.addEntity(tmpl,[location.ref_,CVelocity(dir).ref_].staticArray);
|
||||||
}
|
}
|
||||||
//launcher.manager.addEntity(tmpl);//,[location.ref_].staticArray);
|
//gEntityManager.addEntity(tmpl);//,[location.ref_].staticArray);
|
||||||
|
|
||||||
//launcher.manager.addEntity(space_invaders.bullet_tmpl[0]);
|
//gEntityManager.addEntity(space_invaders.bullet_tmpl[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1627,7 +1577,7 @@ struct PartsDestroySystem
|
||||||
|
|
||||||
void onCreate()
|
void onCreate()
|
||||||
{
|
{
|
||||||
flashes_emitter = launcher.manager.allocateTemplate(
|
flashes_emitter = gEntityManager.allocateTemplate(
|
||||||
[
|
[
|
||||||
becsID!CVelocity, becsID!CLocation, becsID!CParticleEmitter,
|
becsID!CVelocity, becsID!CLocation, becsID!CParticleEmitter,
|
||||||
becsID!CParticleEmitterTime, becsID!CTargetParent, becsID!CDepth
|
becsID!CParticleEmitterTime, becsID!CTargetParent, becsID!CDepth
|
||||||
|
|
@ -1637,7 +1587,7 @@ struct PartsDestroySystem
|
||||||
|
|
||||||
void onDestroy()
|
void onDestroy()
|
||||||
{
|
{
|
||||||
launcher.manager.freeTemplate(flashes_emitter);
|
gEntityManager.freeTemplate(flashes_emitter);
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleEvent(Entity* entity, EDestroyedChild event)
|
void handleEvent(Entity* entity, EDestroyedChild event)
|
||||||
|
|
@ -1653,7 +1603,7 @@ struct PartsDestroySystem
|
||||||
{
|
{
|
||||||
if(child == event.id)
|
if(child == event.id)
|
||||||
{
|
{
|
||||||
Entity* child_entity = launcher.manager.getEntity(child);
|
Entity* child_entity = gEntityManager.getEntity(child);
|
||||||
if(child_entity)
|
if(child_entity)
|
||||||
{
|
{
|
||||||
CLocation location;
|
CLocation location;
|
||||||
|
|
@ -1665,8 +1615,8 @@ struct PartsDestroySystem
|
||||||
if(target_location)location = *target_location;
|
if(target_location)location = *target_location;
|
||||||
|
|
||||||
*flashes_emitter.getComponent!CTargetParent() = *target_parent;
|
*flashes_emitter.getComponent!CTargetParent() = *target_parent;
|
||||||
if(target_depth)child = launcher.manager.addEntity(flashes_emitter, [target_depth.ref_, location.ref_].staticArray).id;
|
if(target_depth)child = gEntityManager.addEntity(flashes_emitter, [target_depth.ref_, location.ref_].staticArray).id;
|
||||||
else child = launcher.manager.addEntity(flashes_emitter, [location.ref_].staticArray).id;
|
else child = gEntityManager.addEntity(flashes_emitter, [location.ref_].staticArray).id;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -1677,7 +1627,7 @@ struct PartsDestroySystem
|
||||||
{
|
{
|
||||||
if(init.type == CInit.Type.boss)
|
if(init.type == CInit.Type.boss)
|
||||||
{
|
{
|
||||||
launcher.manager.addComponents(entity.id, CHitPoints(100), CShootGrid());
|
gEntityManager.addComponents(entity.id, CHitPoints(100), CShootGrid());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1712,7 +1662,7 @@ struct ClampPositionSystem
|
||||||
foreach(i;0..data.length)
|
foreach(i;0..data.length)
|
||||||
{
|
{
|
||||||
if(data.locations[i].x < 0 || data.locations[i].x > space_invaders.map_size.x ||
|
if(data.locations[i].x < 0 || data.locations[i].x > space_invaders.map_size.x ||
|
||||||
data.locations[i].y < 0 || data.locations[i].y > space_invaders.map_size.y)launcher.manager.removeEntity(data.entities[i].id);
|
data.locations[i].y < 0 || data.locations[i].y > space_invaders.map_size.y)gEntityManager.removeEntity(data.entities[i].id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*else if(data.side_move)
|
/*else if(data.side_move)
|
||||||
|
|
@ -1722,7 +1672,7 @@ struct ClampPositionSystem
|
||||||
if(data.locations[i].x < 0)
|
if(data.locations[i].x < 0)
|
||||||
{
|
{
|
||||||
//data.locations[i].x = 0;
|
//data.locations[i].x = 0;
|
||||||
//launcher.manager.sendEvent(data.entities[i].id,EChangeDirection(Direction.right));
|
//gEntityManager.sendEvent(data.entities[i].id,EChangeDirection(Direction.right));
|
||||||
if(data.side_move[i].group == -1)
|
if(data.side_move[i].group == -1)
|
||||||
{
|
{
|
||||||
if(data.velocity[i].x < 0)data.velocity[i].x = -data.velocity[i].x;
|
if(data.velocity[i].x < 0)data.velocity[i].x = -data.velocity[i].x;
|
||||||
|
|
@ -1735,7 +1685,7 @@ struct ClampPositionSystem
|
||||||
else if(data.locations[i].x > space_invaders.map_size.x)
|
else if(data.locations[i].x > space_invaders.map_size.x)
|
||||||
{
|
{
|
||||||
//data.locations[i].x = space_invaders.map_size.x;
|
//data.locations[i].x = space_invaders.map_size.x;
|
||||||
//launcher.manager.sendEvent(data.entities[i].id,EChangeDirection(Direction.left));
|
//gEntityManager.sendEvent(data.entities[i].id,EChangeDirection(Direction.left));
|
||||||
if(data.side_move[i].group == -1)
|
if(data.side_move[i].group == -1)
|
||||||
{
|
{
|
||||||
if(data.velocity[i].x > 0)data.velocity[i].x = -data.velocity[i].x;
|
if(data.velocity[i].x > 0)data.velocity[i].x = -data.velocity[i].x;
|
||||||
|
|
@ -1868,7 +1818,7 @@ struct ParticleSystem
|
||||||
foreach(i;0..data.length)
|
foreach(i;0..data.length)
|
||||||
{
|
{
|
||||||
data.particle[i].life -= launcher.deltaTime;
|
data.particle[i].life -= launcher.deltaTime;
|
||||||
if(data.particle[i].life < 0)launcher.manager.removeEntity(data.entitiy[i].id);
|
if(data.particle[i].life < 0)gEntityManager.removeEntity(data.entitiy[i].id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1889,7 +1839,7 @@ struct RotateToTargetSystem
|
||||||
{
|
{
|
||||||
foreach(i;0..data.length)
|
foreach(i;0..data.length)
|
||||||
{
|
{
|
||||||
Entity* target = launcher.manager.getEntity(data.target[i].target);
|
Entity* target = gEntityManager.getEntity(data.target[i].target);
|
||||||
if(target)
|
if(target)
|
||||||
{
|
{
|
||||||
CLocation* target_loc = target.getComponent!CLocation;
|
CLocation* target_loc = target.getComponent!CLocation;
|
||||||
|
|
@ -1937,11 +1887,11 @@ struct ShipTargetSystem
|
||||||
|
|
||||||
bool onBegin()
|
bool onBegin()
|
||||||
{
|
{
|
||||||
Entity* ship = launcher.manager.getEntity(player_ship);
|
Entity* ship = gEntityManager.getEntity(player_ship);
|
||||||
if(ship is null)
|
if(ship is null)
|
||||||
{
|
{
|
||||||
launcher.manager.callEntitiesFunction!CShipIterator(&iterateShips);
|
gEntityManager.callEntitiesFunction!CShipIterator(&iterateShips);
|
||||||
ship = launcher.manager.getEntity(player_ship);
|
ship = gEntityManager.getEntity(player_ship);
|
||||||
if(ship is null)return false;
|
if(ship is null)return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -1992,7 +1942,7 @@ struct CShipIterator
|
||||||
|
|
||||||
void onCreate()
|
void onCreate()
|
||||||
{
|
{
|
||||||
flashes_emitter = launcher.manager.allocateTemplate(
|
flashes_emitter = gEntityManager.allocateTemplate(
|
||||||
[
|
[
|
||||||
becsID!CVelocity, becsID!CLocation, becsID!CParticleEmitter,
|
becsID!CVelocity, becsID!CLocation, becsID!CParticleEmitter,
|
||||||
becsID!CParticleEmitterTime, becsID!CTargetParent
|
becsID!CParticleEmitterTime, becsID!CTargetParent
|
||||||
|
|
@ -2002,7 +1952,7 @@ struct CShipIterator
|
||||||
|
|
||||||
void onDestroy()
|
void onDestroy()
|
||||||
{
|
{
|
||||||
launcher.manager.freeTemplate(flashes_emitter);
|
gEntityManager.freeTemplate(flashes_emitter);
|
||||||
}
|
}
|
||||||
|
|
||||||
void onRemoveEntity(EntitiesData data)
|
void onRemoveEntity(EntitiesData data)
|
||||||
|
|
@ -2013,18 +1963,18 @@ struct CShipIterator
|
||||||
case CSpawnUponDeath.Type.flashes_emitter:
|
case CSpawnUponDeath.Type.flashes_emitter:
|
||||||
if(data.parent)
|
if(data.parent)
|
||||||
{
|
{
|
||||||
/*Entity* parent_entity = launcher.manager.getEntity(data.parent[0].parent);
|
/*Entity* parent_entity = gEntityManager.getEntity(data.parent[0].parent);
|
||||||
CChildren* children = entity.getComponent!CChildren;
|
CChildren* children = entity.getComponent!CChildren;
|
||||||
foreach(ref EntityID child; children.childern)
|
foreach(ref EntityID child; children.childern)
|
||||||
{
|
{
|
||||||
if(child == event.id)
|
if(child == event.id)
|
||||||
{
|
{
|
||||||
Entity* child_entity = launcher.manager.getEntity(child);
|
Entity* child_entity = gEntityManager.getEntity(child);
|
||||||
if(child_entity)
|
if(child_entity)
|
||||||
{
|
{
|
||||||
*flashes_emitter.getComponent!CTargetParent = data.parent[0];
|
*flashes_emitter.getComponent!CTargetParent = data.parent[0];
|
||||||
launcher.manager.addEntity(flashes_emitter);
|
gEntityManager.addEntity(flashes_emitter);
|
||||||
//child = launcher.manager.addEntity(flashes_emitter);
|
//child = gEntityManager.addEntity(flashes_emitter);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -2052,92 +2002,92 @@ void spaceInvadersRegister()
|
||||||
space_invaders.texture.create();
|
space_invaders.texture.create();
|
||||||
space_invaders.texture.load("assets/textures/atlas.png");
|
space_invaders.texture.load("assets/textures/atlas.png");
|
||||||
|
|
||||||
launcher.manager.beginRegister();
|
gEntityManager.beginRegister();
|
||||||
|
|
||||||
launcher.manager.registerDependency(ShootGridDependency);
|
gEntityManager.registerDependency(ShootGridDependency);
|
||||||
|
|
||||||
registerRenderingModule(launcher.manager);
|
registerRenderingModule(gEntityManager);
|
||||||
|
|
||||||
launcher.manager.registerComponent!CLocation;
|
gEntityManager.registerComponent!CLocation;
|
||||||
launcher.manager.registerComponent!CTexCoords;
|
gEntityManager.registerComponent!CTexCoords;
|
||||||
//launcher.manager.registerComponent!CTexture;
|
//gEntityManager.registerComponent!CTexture;
|
||||||
launcher.manager.registerComponent!CInput;
|
gEntityManager.registerComponent!CInput;
|
||||||
launcher.manager.registerComponent!CShip;
|
gEntityManager.registerComponent!CShip;
|
||||||
launcher.manager.registerComponent!CEnemy;
|
gEntityManager.registerComponent!CEnemy;
|
||||||
launcher.manager.registerComponent!CScale;
|
gEntityManager.registerComponent!CScale;
|
||||||
launcher.manager.registerComponent!CShootDirection;
|
gEntityManager.registerComponent!CShootDirection;
|
||||||
launcher.manager.registerComponent!CAutoShoot;
|
gEntityManager.registerComponent!CAutoShoot;
|
||||||
launcher.manager.registerComponent!CWeapon;
|
gEntityManager.registerComponent!CWeapon;
|
||||||
launcher.manager.registerComponent!CVelocity;
|
gEntityManager.registerComponent!CVelocity;
|
||||||
launcher.manager.registerComponent!CBullet;
|
gEntityManager.registerComponent!CBullet;
|
||||||
launcher.manager.registerComponent!CSideMove;
|
gEntityManager.registerComponent!CSideMove;
|
||||||
launcher.manager.registerComponent!CDepth;
|
gEntityManager.registerComponent!CDepth;
|
||||||
launcher.manager.registerComponent!CShootGrid;
|
gEntityManager.registerComponent!CShootGrid;
|
||||||
launcher.manager.registerComponent!CGuild;
|
gEntityManager.registerComponent!CGuild;
|
||||||
launcher.manager.registerComponent!CHitPoints;
|
gEntityManager.registerComponent!CHitPoints;
|
||||||
launcher.manager.registerComponent!CHitMark;
|
gEntityManager.registerComponent!CHitMark;
|
||||||
launcher.manager.registerComponent!CUpgrade;
|
gEntityManager.registerComponent!CUpgrade;
|
||||||
launcher.manager.registerComponent!CParticle;
|
gEntityManager.registerComponent!CParticle;
|
||||||
launcher.manager.registerComponent!CMaxHitPoints;
|
gEntityManager.registerComponent!CMaxHitPoints;
|
||||||
launcher.manager.registerComponent!CAnimation;
|
gEntityManager.registerComponent!CAnimation;
|
||||||
launcher.manager.registerComponent!CRotation;
|
gEntityManager.registerComponent!CRotation;
|
||||||
launcher.manager.registerComponent!CAnimationLooped;
|
gEntityManager.registerComponent!CAnimationLooped;
|
||||||
launcher.manager.registerComponent!CDamping;
|
gEntityManager.registerComponent!CDamping;
|
||||||
launcher.manager.registerComponent!CTargetParent;
|
gEntityManager.registerComponent!CTargetParent;
|
||||||
launcher.manager.registerComponent!CTarget;
|
gEntityManager.registerComponent!CTarget;
|
||||||
launcher.manager.registerComponent!CTargetPlayerShip;
|
gEntityManager.registerComponent!CTargetPlayerShip;
|
||||||
launcher.manager.registerComponent!CChildren;
|
gEntityManager.registerComponent!CChildren;
|
||||||
launcher.manager.registerComponent!CWeaponLocation;
|
gEntityManager.registerComponent!CWeaponLocation;
|
||||||
launcher.manager.registerComponent!CVelocityFactor;
|
gEntityManager.registerComponent!CVelocityFactor;
|
||||||
launcher.manager.registerComponent!CInit;
|
gEntityManager.registerComponent!CInit;
|
||||||
launcher.manager.registerComponent!CBoss;
|
gEntityManager.registerComponent!CBoss;
|
||||||
launcher.manager.registerComponent!CParts;
|
gEntityManager.registerComponent!CParts;
|
||||||
launcher.manager.registerComponent!CColliderScale;
|
gEntityManager.registerComponent!CColliderScale;
|
||||||
launcher.manager.registerComponent!CParticleEmitter;
|
gEntityManager.registerComponent!CParticleEmitter;
|
||||||
launcher.manager.registerComponent!CParticleEmitterTime;
|
gEntityManager.registerComponent!CParticleEmitterTime;
|
||||||
launcher.manager.registerComponent!CSpawnUponDeath;
|
gEntityManager.registerComponent!CSpawnUponDeath;
|
||||||
launcher.manager.registerComponent!CShootWaveUponDeath;
|
gEntityManager.registerComponent!CShootWaveUponDeath;
|
||||||
launcher.manager.registerComponent!CShootGridMask;
|
gEntityManager.registerComponent!CShootGridMask;
|
||||||
|
|
||||||
launcher.manager.registerEvent!EChangeDirection;
|
gEntityManager.registerEvent!EChangeDirection;
|
||||||
launcher.manager.registerEvent!EDamage;
|
gEntityManager.registerEvent!EDamage;
|
||||||
launcher.manager.registerEvent!EUpgrade;
|
gEntityManager.registerEvent!EUpgrade;
|
||||||
launcher.manager.registerEvent!EDeath;
|
gEntityManager.registerEvent!EDeath;
|
||||||
launcher.manager.registerEvent!EDestroyedChild;
|
gEntityManager.registerEvent!EDestroyedChild;
|
||||||
launcher.manager.registerEvent!EBulletHit;
|
gEntityManager.registerEvent!EBulletHit;
|
||||||
|
|
||||||
//launcher.manager.registerSystem!MoveSystem(0);
|
//gEntityManager.registerSystem!MoveSystem(0);
|
||||||
launcher.manager.registerSystem!DrawSystem(100);
|
gEntityManager.registerSystem!DrawSystem(100);
|
||||||
launcher.manager.registerSystem!InputMovementSystem(-100);
|
gEntityManager.registerSystem!InputMovementSystem(-100);
|
||||||
//launcher.manager.registerSystem!MovementSystem(-99);
|
//gEntityManager.registerSystem!MovementSystem(-99);
|
||||||
launcher.manager.registerSystem!MoveSystem(-99);
|
gEntityManager.registerSystem!MoveSystem(-99);
|
||||||
launcher.manager.registerSystem!ClampPositionSystem(-90);
|
gEntityManager.registerSystem!ClampPositionSystem(-90);
|
||||||
launcher.manager.registerSystem!ShootingSystem(0);
|
gEntityManager.registerSystem!ShootingSystem(0);
|
||||||
launcher.manager.registerSystem!ChangeDirectionSystem(0);
|
gEntityManager.registerSystem!ChangeDirectionSystem(0);
|
||||||
launcher.manager.registerSystem!BulletsCollisionSystem(-70);
|
gEntityManager.registerSystem!BulletsCollisionSystem(-70);
|
||||||
launcher.manager.registerSystem!ShootGridManager(-80);
|
gEntityManager.registerSystem!ShootGridManager(-80);
|
||||||
launcher.manager.registerSystem!ShootGridCleaner(-101);
|
gEntityManager.registerSystem!ShootGridCleaner(-101);
|
||||||
launcher.manager.registerSystem!HitPointsSystem(0);
|
gEntityManager.registerSystem!HitPointsSystem(0);
|
||||||
launcher.manager.registerSystem!HitMarkingSystem(-100);
|
gEntityManager.registerSystem!HitMarkingSystem(-100);
|
||||||
launcher.manager.registerSystem!UpgradeCollisionSystem(-70);
|
gEntityManager.registerSystem!UpgradeCollisionSystem(-70);
|
||||||
launcher.manager.registerSystem!UpgradeSystem(-100);
|
gEntityManager.registerSystem!UpgradeSystem(-100);
|
||||||
launcher.manager.registerSystem!ParticleSystem(-100);
|
gEntityManager.registerSystem!ParticleSystem(-100);
|
||||||
launcher.manager.registerSystem!AnimationSystem(-100);
|
gEntityManager.registerSystem!AnimationSystem(-100);
|
||||||
launcher.manager.registerSystem!DampingSystem(-101);
|
gEntityManager.registerSystem!DampingSystem(-101);
|
||||||
launcher.manager.registerSystem!MoveToParentTargetSystem(-98);
|
gEntityManager.registerSystem!MoveToParentTargetSystem(-98);
|
||||||
launcher.manager.registerSystem!ParentOwnerSystem(-101);
|
gEntityManager.registerSystem!ParentOwnerSystem(-101);
|
||||||
launcher.manager.registerSystem!ShipWeaponSystem(-100);
|
gEntityManager.registerSystem!ShipWeaponSystem(-100);
|
||||||
launcher.manager.registerSystem!ParticleEmittingSystem(-95);
|
gEntityManager.registerSystem!ParticleEmittingSystem(-95);
|
||||||
launcher.manager.registerSystem!RotateToTargetSystem(-100);
|
gEntityManager.registerSystem!RotateToTargetSystem(-100);
|
||||||
launcher.manager.registerSystem!ShipTargetSystem(-110);
|
gEntityManager.registerSystem!ShipTargetSystem(-110);
|
||||||
launcher.manager.registerSystem!CShipIterator(-100);
|
gEntityManager.registerSystem!CShipIterator(-100);
|
||||||
launcher.manager.registerSystem!PartsDestroySystem(-80);
|
gEntityManager.registerSystem!PartsDestroySystem(-80);
|
||||||
launcher.manager.registerSystem!ChildDestroySystem(-110);
|
gEntityManager.registerSystem!ChildDestroySystem(-110);
|
||||||
launcher.manager.registerSystem!ShootWaveSystem(-100);
|
gEntityManager.registerSystem!ShootWaveSystem(-100);
|
||||||
//launcher.manager.registerSystem!SpawnUponDeathSystem(-110);
|
//gEntityManager.registerSystem!SpawnUponDeathSystem(-110);
|
||||||
launcher.manager.registerSystem!CollisionMaskSystem(-100);
|
gEntityManager.registerSystem!CollisionMaskSystem(-100);
|
||||||
|
|
||||||
launcher.manager.endRegister();
|
gEntityManager.endRegister();
|
||||||
}
|
}
|
||||||
|
|
||||||
void spaceInvadersStart()
|
void spaceInvadersStart()
|
||||||
|
|
@ -2146,9 +2096,9 @@ void spaceInvadersStart()
|
||||||
// space_invaders.shoot_grid = Mallocator.make!ShootGrid;
|
// space_invaders.shoot_grid = Mallocator.make!ShootGrid;
|
||||||
// space_invaders.shoot_grid.create(ivec2(80,60), vec2(5,5));
|
// space_invaders.shoot_grid.create(ivec2(80,60), vec2(5,5));
|
||||||
|
|
||||||
space_invaders.shoot_grid = launcher.manager.getSystem!ShootGridManager().grid;
|
space_invaders.shoot_grid = gEntityManager.getSystem!ShootGridManager().grid;
|
||||||
|
|
||||||
DrawSystem* draw_system = launcher.manager.getSystem!DrawSystem;
|
DrawSystem* draw_system = gEntityManager.getSystem!DrawSystem;
|
||||||
draw_system.default_data.color = 0x80808080;
|
draw_system.default_data.color = 0x80808080;
|
||||||
draw_system.default_data.texture = space_invaders.texture;
|
draw_system.default_data.texture = space_invaders.texture;
|
||||||
|
|
||||||
|
|
@ -2216,9 +2166,9 @@ void spaceInvadersStart()
|
||||||
launcher.gui_manager.addSystem(becsID!ShootWaveSystem,"Shoot Wave System");
|
launcher.gui_manager.addSystem(becsID!ShootWaveSystem,"Shoot Wave System");
|
||||||
//launcher.gui_manager.addSystem(becsID!SpawnUponDeathSystem,"Child Destroy System");
|
//launcher.gui_manager.addSystem(becsID!SpawnUponDeathSystem,"Child Destroy System");
|
||||||
|
|
||||||
//launcher.manager.getSystem(becsID!CleanSystem).disable();
|
//gEntityManager.getSystem(becsID!CleanSystem).disable();
|
||||||
{
|
{
|
||||||
space_invaders.ship_tmpl = launcher.manager.allocateTemplate(
|
space_invaders.ship_tmpl = gEntityManager.allocateTemplate(
|
||||||
[becsID!CVelocity, becsID!CColor, becsID!CHitMark, becsID!CHitPoints,
|
[becsID!CVelocity, becsID!CColor, becsID!CHitMark, becsID!CHitPoints,
|
||||||
becsID!CLocation, becsID!CTexCoords, becsID!CInput,
|
becsID!CLocation, becsID!CTexCoords, becsID!CInput,
|
||||||
becsID!CShip, becsID!CScale, becsID!CColliderScale,
|
becsID!CShip, becsID!CScale, becsID!CColliderScale,
|
||||||
|
|
@ -2234,12 +2184,12 @@ void spaceInvadersStart()
|
||||||
space_invaders.ship_tmpl.getComponent!CColliderScale().value = vec2(26,24);
|
space_invaders.ship_tmpl.getComponent!CColliderScale().value = vec2(26,24);
|
||||||
space_invaders.ship_tmpl.getComponent!CVelocityFactor().value = vec2(0.5,0.5);
|
space_invaders.ship_tmpl.getComponent!CVelocityFactor().value = vec2(0.5,0.5);
|
||||||
|
|
||||||
launcher.manager.addEntity(space_invaders.ship_tmpl,[CLocation(vec2(64,64)).ref_].staticArray);
|
gEntityManager.addEntity(space_invaders.ship_tmpl,[CLocation(vec2(64,64)).ref_].staticArray);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
ushort[6] components = [becsID!CLocation, becsID!CTexCoords, becsID!CVelocity, becsID!CScale, becsID!CBullet, becsID!CGuild];
|
ushort[6] components = [becsID!CLocation, becsID!CTexCoords, becsID!CVelocity, becsID!CScale, becsID!CBullet, becsID!CGuild];
|
||||||
space_invaders.laser_tmpl = launcher.manager.allocateTemplate(components);
|
space_invaders.laser_tmpl = gEntityManager.allocateTemplate(components);
|
||||||
|
|
||||||
space_invaders.laser_tmpl.getComponent!CTexCoords().value = 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);
|
||||||
|
|
@ -2255,7 +2205,7 @@ void spaceInvadersStart()
|
||||||
EntityID grouped_id;
|
EntityID grouped_id;
|
||||||
|
|
||||||
{
|
{
|
||||||
boss_tmpl = launcher.manager.allocateTemplate(
|
boss_tmpl = gEntityManager.allocateTemplate(
|
||||||
[becsID!CColor, becsID!CHitMark, becsID!CParts, becsID!CLocation,
|
[becsID!CColor, becsID!CHitMark, becsID!CParts, becsID!CLocation,
|
||||||
becsID!CTexCoords, becsID!CScale, becsID!CEnemy,
|
becsID!CTexCoords, becsID!CScale, becsID!CEnemy,
|
||||||
becsID!CBoss, becsID!CGuild, becsID!CInit,
|
becsID!CBoss, becsID!CGuild, becsID!CInit,
|
||||||
|
|
@ -2278,7 +2228,7 @@ void spaceInvadersStart()
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
tower_tmpl = launcher.manager.allocateTemplate(
|
tower_tmpl = gEntityManager.allocateTemplate(
|
||||||
[becsID!CColor, becsID!CHitMark, becsID!CHitPoints, becsID!CLocation,
|
[becsID!CColor, becsID!CHitMark, becsID!CHitPoints, becsID!CLocation,
|
||||||
becsID!CTexCoords, becsID!CScale, becsID!CEnemy,
|
becsID!CTexCoords, becsID!CScale, becsID!CEnemy,
|
||||||
becsID!CShootGrid, becsID!CGuild, becsID!CInit,
|
becsID!CShootGrid, becsID!CGuild, becsID!CInit,
|
||||||
|
|
@ -2292,7 +2242,7 @@ void spaceInvadersStart()
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
space_invaders.enemy_tmpl = launcher.manager.allocateTemplate(
|
space_invaders.enemy_tmpl = gEntityManager.allocateTemplate(
|
||||||
[becsID!CWeaponLocation, becsID!CColor, becsID!CHitMark, becsID!CHitPoints,
|
[becsID!CWeaponLocation, becsID!CColor, becsID!CHitMark, becsID!CHitPoints,
|
||||||
becsID!CVelocity, becsID!CAutoShoot, becsID!CLocation,
|
becsID!CVelocity, becsID!CAutoShoot, becsID!CLocation,
|
||||||
becsID!CTexCoords, becsID!CScale, becsID!CWeapon,
|
becsID!CTexCoords, becsID!CScale, becsID!CWeapon,
|
||||||
|
|
@ -2308,81 +2258,81 @@ void spaceInvadersStart()
|
||||||
|
|
||||||
Entity* current_entity;
|
Entity* current_entity;
|
||||||
|
|
||||||
current_entity = launcher.manager.addEntity(space_invaders.enemy_tmpl,[CLocation(vec2(32,space_invaders.map_size.y - 16)).ref_].staticArray);
|
current_entity = gEntityManager.addEntity(space_invaders.enemy_tmpl,[CLocation(vec2(32,space_invaders.map_size.y - 16)).ref_].staticArray);
|
||||||
launcher.manager.addComponents(current_entity.id,CSideMove(0));
|
gEntityManager.addComponents(current_entity.id,CSideMove(0));
|
||||||
|
|
||||||
//loc_comp.value = vec2(128,space_invaders.map_size.y - 16);
|
//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);
|
current_entity = gEntityManager.addEntity(space_invaders.enemy_tmpl,[CLocation(vec2(128,space_invaders.map_size.y - 16)).ref_].staticArray);
|
||||||
launcher.manager.addComponents(current_entity.id,CSideMove(-1));
|
gEntityManager.addComponents(current_entity.id,CSideMove(-1));
|
||||||
|
|
||||||
enemy_id = current_entity.id;
|
enemy_id = current_entity.id;
|
||||||
//enemy_tmpl = launcher.manager.allocateTemplate(current_entity.id);
|
//enemy_tmpl = gEntityManager.allocateTemplate(current_entity.id);
|
||||||
|
|
||||||
//loc_comp.value = vec2(256,space_invaders.map_size.y - 16);
|
//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);
|
gEntityManager.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);
|
//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);
|
current_entity = gEntityManager.addEntity(space_invaders.enemy_tmpl,[CLocation(vec2(0,space_invaders.map_size.y - 16)).ref_].staticArray);
|
||||||
launcher.manager.addComponents(current_entity.id,CSideMove(0));
|
gEntityManager.addComponents(current_entity.id,CSideMove(0));
|
||||||
|
|
||||||
grouped_id = current_entity.id;
|
grouped_id = current_entity.id;
|
||||||
//grouped_tmpl = launcher.manager.allocateTemplate(current_entity.id);
|
//grouped_tmpl = gEntityManager.allocateTemplate(current_entity.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
EntityTemplate* upgrade_tmpl;
|
EntityTemplate* upgrade_tmpl;
|
||||||
|
|
||||||
{
|
{
|
||||||
upgrade_tmpl = launcher.manager.allocateTemplate([becsID!CVelocity, becsID!CLocation, becsID!CTexCoords, becsID!CScale, becsID!CUpgrade, becsID!CAnimationLooped, becsID!CAnimation].staticArray);
|
upgrade_tmpl = gEntityManager.allocateTemplate([becsID!CVelocity, becsID!CLocation, becsID!CTexCoords, becsID!CScale, becsID!CUpgrade, becsID!CAnimationLooped, becsID!CAnimation].staticArray);
|
||||||
upgrade_tmpl.getComponent!CTexCoords().value = 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.05);
|
upgrade_tmpl.getComponent!CVelocity().value = vec2(0,-0.05);
|
||||||
*upgrade_tmpl.getComponent!CAnimation = CAnimation(HitPointsSystem.upgrade_laser_frames, 0, 0.75);
|
*upgrade_tmpl.getComponent!CAnimation = CAnimation(HitPointsSystem.upgrade_laser_frames, 0, 0.75);
|
||||||
}
|
}
|
||||||
|
|
||||||
launcher.manager.commit();
|
gEntityManager.commit();
|
||||||
|
|
||||||
enemy_tmpl = launcher.manager.allocateTemplate(enemy_id);
|
enemy_tmpl = gEntityManager.allocateTemplate(enemy_id);
|
||||||
grouped_tmpl = launcher.manager.allocateTemplate(grouped_id);
|
grouped_tmpl = gEntityManager.allocateTemplate(grouped_id);
|
||||||
|
|
||||||
space_invaders.bullet_tmpl[0] = launcher.manager.allocateTemplate(
|
space_invaders.bullet_tmpl[0] = gEntityManager.allocateTemplate(
|
||||||
[becsID!CLocation, becsID!CTexCoords, becsID!CVelocity,
|
[becsID!CLocation, becsID!CTexCoords, becsID!CVelocity,
|
||||||
becsID!CScale, becsID!CBullet, becsID!CGuild].staticArray
|
becsID!CScale, becsID!CBullet, becsID!CGuild].staticArray
|
||||||
);
|
);
|
||||||
space_invaders.bullet_tmpl[0].getComponent!CTexCoords().value = 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] = gEntityManager.allocateTemplate(space_invaders.bullet_tmpl[0]);
|
||||||
space_invaders.bullet_tmpl[2] = launcher.manager.allocateTemplate(space_invaders.bullet_tmpl[0]);
|
space_invaders.bullet_tmpl[2] = gEntityManager.allocateTemplate(space_invaders.bullet_tmpl[0]);
|
||||||
space_invaders.bullet_tmpl[2].getComponent!CTexCoords().value = 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] = gEntityManager.allocateTemplate(space_invaders.bullet_tmpl[0]);
|
||||||
space_invaders.bullet_tmpl[3].getComponent!CTexCoords().value = 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!CTexCoords().value = 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] = gEntityManager.allocateTemplate(space_invaders.bullet_tmpl[0]);
|
||||||
|
|
||||||
launcher.gui_manager.addTemplate(enemy_tmpl,"Enemy");
|
launcher.gui_manager.addTemplate(enemy_tmpl,"Enemy");
|
||||||
launcher.gui_manager.addTemplate(grouped_tmpl,"Grouped enemy");
|
launcher.gui_manager.addTemplate(grouped_tmpl,"Grouped enemy");
|
||||||
launcher.gui_manager.addTemplate(launcher.manager.allocateTemplate(space_invaders.ship_tmpl),"Ship");
|
launcher.gui_manager.addTemplate(gEntityManager.allocateTemplate(space_invaders.ship_tmpl),"Ship");
|
||||||
launcher.gui_manager.addTemplate(launcher.manager.allocateTemplate(space_invaders.laser_tmpl),"Laser");
|
launcher.gui_manager.addTemplate(gEntityManager.allocateTemplate(space_invaders.laser_tmpl),"Laser");
|
||||||
launcher.gui_manager.addTemplate(upgrade_tmpl,"Upgrade");
|
launcher.gui_manager.addTemplate(upgrade_tmpl,"Upgrade");
|
||||||
launcher.gui_manager.addTemplate(tower_tmpl,"Tower");
|
launcher.gui_manager.addTemplate(tower_tmpl,"Tower");
|
||||||
launcher.gui_manager.addTemplate(boss_tmpl,"Boss");
|
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(gEntityManager.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(gEntityManager.allocateTemplate(space_invaders.bullet_tmpl[4]),"Laser");
|
||||||
//launcher.gui_manager.addTemplate(launcher.manager.allocateTemplate(space_invaders.bullet_tmpl[5]),"Laser");
|
//launcher.gui_manager.addTemplate(gEntityManager.allocateTemplate(space_invaders.bullet_tmpl[5]),"Laser");
|
||||||
}
|
}
|
||||||
|
|
||||||
void spaceInvadersEnd()
|
void spaceInvadersEnd()
|
||||||
{
|
{
|
||||||
/*launcher.manager.getSystem(becsID!DrawSystem).disable();
|
/*gEntityManager.getSystem(becsID!DrawSystem).disable();
|
||||||
launcher.manager.getSystem(becsID!InputMovementSystem).disable();
|
gEntityManager.getSystem(becsID!InputMovementSystem).disable();
|
||||||
launcher.manager.getSystem(becsID!ShootingSystem).disable();
|
gEntityManager.getSystem(becsID!ShootingSystem).disable();
|
||||||
launcher.manager.getSystem(becsID!MovementSystem).disable();
|
gEntityManager.getSystem(becsID!MovementSystem).disable();
|
||||||
launcher.manager.getSystem(becsID!ClampPositionSystem).disable();
|
gEntityManager.getSystem(becsID!ClampPositionSystem).disable();
|
||||||
launcher.manager.getSystem(becsID!ShootGridCleaner).disable();*/
|
gEntityManager.getSystem(becsID!ShootGridCleaner).disable();*/
|
||||||
|
|
||||||
//launcher.manager.freeTemplate(space_invaders.enemy_tmpl);
|
//gEntityManager.freeTemplate(space_invaders.enemy_tmpl);
|
||||||
Mallocator.dispose(space_invaders);
|
Mallocator.dispose(space_invaders);
|
||||||
space_invaders = null;
|
space_invaders = null;
|
||||||
}
|
}
|
||||||
|
|
@ -2404,13 +2354,13 @@ bool spaceInvadersLoop()
|
||||||
{
|
{
|
||||||
if(igCheckbox("Move system",&simple.move_system))
|
if(igCheckbox("Move system",&simple.move_system))
|
||||||
{
|
{
|
||||||
if(simple.move_system)launcher.manager.getSystem(becsID!MoveSystem).enable();
|
if(simple.move_system)gEntityManager.getSystem(becsID!MoveSystem).enable();
|
||||||
else launcher.manager.getSystem(becsID!MoveSystem).disable();
|
else gEntityManager.getSystem(becsID!MoveSystem).disable();
|
||||||
}
|
}
|
||||||
if(igCheckbox("Draw system",&simple.draw_system))
|
if(igCheckbox("Draw system",&simple.draw_system))
|
||||||
{
|
{
|
||||||
if(simple.draw_system)launcher.manager.getSystem(becsID!DrawSystem).enable();
|
if(simple.draw_system)gEntityManager.getSystem(becsID!DrawSystem).enable();
|
||||||
else launcher.manager.getSystem(becsID!DrawSystem).disable();
|
else gEntityManager.getSystem(becsID!DrawSystem).disable();
|
||||||
}
|
}
|
||||||
igPushButtonRepeat(true);
|
igPushButtonRepeat(true);
|
||||||
igColumns(3,null,0);
|
igColumns(3,null,0);
|
||||||
|
|
@ -2432,11 +2382,11 @@ bool spaceInvadersLoop()
|
||||||
igColumns(1,null,0);
|
igColumns(1,null,0);
|
||||||
if(igButton("Clear",ImVec2(-1,0)))
|
if(igButton("Clear",ImVec2(-1,0)))
|
||||||
{
|
{
|
||||||
launcher.manager.getSystem(becsID!CleanSystem).enable();
|
gEntityManager.getSystem(becsID!CleanSystem).enable();
|
||||||
launcher.manager.begin();
|
gEntityManager.begin();
|
||||||
launcher.manager.update();
|
gEntityManager.update();
|
||||||
launcher.manager.end();
|
gEntityManager.end();
|
||||||
launcher.manager.getSystem(becsID!CleanSystem).disable();
|
gEntityManager.getSystem(becsID!CleanSystem).disable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
igEnd();
|
igEnd();
|
||||||
|
|
@ -2453,18 +2403,18 @@ bool spaceInvadersLoop()
|
||||||
igEnd();
|
igEnd();
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
launcher.manager.begin();
|
gEntityManager.begin();
|
||||||
if(launcher.multithreading)
|
if(launcher.multithreading)
|
||||||
{
|
{
|
||||||
launcher.job_updater.begin();
|
launcher.job_updater.begin();
|
||||||
launcher.manager.updateMT();
|
gEntityManager.updateMT();
|
||||||
launcher.job_updater.call();
|
launcher.job_updater.call();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
launcher.manager.update();
|
gEntityManager.update();
|
||||||
}
|
}
|
||||||
launcher.manager.end();
|
gEntityManager.end();
|
||||||
|
|
||||||
/*foreach(i;0..1000)//13000)
|
/*foreach(i;0..1000)//13000)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -13,33 +13,39 @@ import app : launcher;
|
||||||
|
|
||||||
import bindbc.sdl;
|
import bindbc.sdl;
|
||||||
|
|
||||||
|
//position component
|
||||||
struct CLocation
|
struct CLocation
|
||||||
{
|
{
|
||||||
|
//adds some extra functionality. Not required. Will be probably removed from library in the future.
|
||||||
mixin ECS.Component;
|
mixin ECS.Component;
|
||||||
|
|
||||||
alias value this;
|
alias value this;//use component as it value
|
||||||
|
|
||||||
|
//default values work properly
|
||||||
vec2 value = vec2(0);
|
vec2 value = vec2(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//scale component
|
||||||
struct CScale
|
struct CScale
|
||||||
{
|
{
|
||||||
mixin ECS.Component;
|
mixin ECS.Component;
|
||||||
|
|
||||||
alias value this;///use component as it value
|
alias value this;//use component as it value
|
||||||
|
|
||||||
vec2 value = vec2(16,16);
|
vec2 value = vec2(16,16);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//rotation component
|
||||||
struct CRotation
|
struct CRotation
|
||||||
{
|
{
|
||||||
mixin ECS.Component;
|
mixin ECS.Component;
|
||||||
|
|
||||||
alias value this;///use component as it value
|
alias value this;//use component as it value
|
||||||
|
|
||||||
float value = 0;
|
float value = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//depth component. Entity with higher depth will be rendered on top
|
||||||
struct CDepth
|
struct CDepth
|
||||||
{
|
{
|
||||||
mixin ECS.Component;
|
mixin ECS.Component;
|
||||||
|
|
@ -49,6 +55,7 @@ struct CDepth
|
||||||
short value;
|
short value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//color component
|
||||||
struct CColor
|
struct CColor
|
||||||
{
|
{
|
||||||
mixin ECS.Component;
|
mixin ECS.Component;
|
||||||
|
|
@ -58,6 +65,7 @@ struct CColor
|
||||||
@GUIColor uint value;
|
@GUIColor uint value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//component used for selection
|
||||||
struct CSelected
|
struct CSelected
|
||||||
{
|
{
|
||||||
mixin ECS.Component;
|
mixin ECS.Component;
|
||||||
|
|
@ -65,11 +73,13 @@ struct CSelected
|
||||||
bool value = false;
|
bool value = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//component indicating that entity should receive input from mouse, keyboard, etc.
|
||||||
struct CInput
|
struct CInput
|
||||||
{
|
{
|
||||||
mixin ECS.Component;
|
mixin ECS.Component;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//component with damping value
|
||||||
struct CDamping
|
struct CDamping
|
||||||
{
|
{
|
||||||
mixin ECS.Component;
|
mixin ECS.Component;
|
||||||
|
|
@ -79,6 +89,7 @@ struct CDamping
|
||||||
@GUIRange(0,9) byte value = 1;
|
@GUIRange(0,9) byte value = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//velocity component
|
||||||
struct CVelocity
|
struct CVelocity
|
||||||
{
|
{
|
||||||
mixin ECS.Component;
|
mixin ECS.Component;
|
||||||
|
|
@ -88,6 +99,7 @@ struct CVelocity
|
||||||
vec2 value = vec2(0,0);
|
vec2 value = vec2(0,0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//factor which is used for velocity masking
|
||||||
struct CVelocityFactor
|
struct CVelocityFactor
|
||||||
{
|
{
|
||||||
mixin ECS.Component;
|
mixin ECS.Component;
|
||||||
|
|
@ -97,30 +109,35 @@ struct CVelocityFactor
|
||||||
vec2 value = vec2(1);
|
vec2 value = vec2(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//flag indicating that entity is static and shouldn't be updated by most systems in every frame
|
||||||
struct CStatic
|
struct CStatic
|
||||||
{
|
{
|
||||||
mixin ECS.Component;
|
mixin ECS.Component;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//system which slowing down entities
|
||||||
struct DampingSystem
|
struct DampingSystem
|
||||||
{
|
{
|
||||||
|
//system will generate up to 32 jobs
|
||||||
mixin ECS.System!32;
|
mixin ECS.System!32;
|
||||||
|
|
||||||
struct EntitiesData
|
struct EntitiesData
|
||||||
{
|
{
|
||||||
uint length;
|
uint length;
|
||||||
const (Entity)[] entity;
|
const (Entity)[] entity; //entity is readonly
|
||||||
@readonly CDamping[] damping;
|
@readonly CDamping[] damping;//damping is readonly. Marking with @readonly will help multithreading algorithm
|
||||||
CVelocity[] velocity;
|
CVelocity[] velocity;//velocity is wirtable as it will be modified for entities in this system
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//20 predefined damping speeds. Gives possibility to store damping as single byte.
|
||||||
float[20] damp = 0;
|
float[20] damp = 0;
|
||||||
|
|
||||||
bool onBegin()
|
bool onBegin()
|
||||||
{
|
{
|
||||||
|
//calculate damping values
|
||||||
foreach(i;0..20)
|
foreach(i;0..20)
|
||||||
{
|
{
|
||||||
damp[i] = powf((0.99 - cast(float)i * 0.01),launcher.delta_time*0.1);
|
damp[i] = powf((0.99 - cast(float)i * 0.01),launcher.deltaTime*0.1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -130,11 +147,13 @@ struct DampingSystem
|
||||||
{
|
{
|
||||||
foreach(i; 0..data.length)
|
foreach(i; 0..data.length)
|
||||||
{
|
{
|
||||||
|
//constantly slow down entity
|
||||||
data.velocity[i] = data.velocity[i] * damp[data.damping[i]];
|
data.velocity[i] = data.velocity[i] * damp[data.damping[i]];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//system used for entity movement
|
||||||
struct MoveSystem
|
struct MoveSystem
|
||||||
{
|
{
|
||||||
mixin ECS.System!64;
|
mixin ECS.System!64;
|
||||||
|
|
@ -144,23 +163,24 @@ struct MoveSystem
|
||||||
uint length;
|
uint length;
|
||||||
CLocation[] location;
|
CLocation[] location;
|
||||||
@readonly CVelocity[] velocity;
|
@readonly CVelocity[] velocity;
|
||||||
@optional @readonly CVelocityFactor[] vel_factor;
|
@optional @readonly CVelocityFactor[] vel_factor;//CVeclocityFactor is not required so entites without this component will be also updated
|
||||||
}
|
}
|
||||||
|
|
||||||
void onUpdate(EntitiesData data)
|
void onUpdate(EntitiesData data)
|
||||||
{
|
{
|
||||||
|
//split into two loops for two types of entities. Doing it in "normal" way by testing data.vel_factor inside loop in every iteration will be probably compiled as same machine code in release build (it works in LDC)
|
||||||
if(data.vel_factor)
|
if(data.vel_factor)
|
||||||
{
|
{
|
||||||
foreach(i; 0..data.length)
|
foreach(i; 0..data.length)
|
||||||
{
|
{
|
||||||
data.location[i] += data.velocity[i] * data.vel_factor[i] * launcher.delta_time;
|
data.location[i] += data.velocity[i] * data.vel_factor[i] * launcher.deltaTime;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
foreach(i; 0..data.length)
|
foreach(i; 0..data.length)
|
||||||
{
|
{
|
||||||
data.location[i] += data.velocity[i] * launcher.delta_time;
|
data.location[i] += data.velocity[i] * launcher.deltaTime;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -227,33 +247,14 @@ struct InputMovementSystem
|
||||||
*JobSystem can split buffers for better data packing.
|
*JobSystem can split buffers for better data packing.
|
||||||
*/
|
*/
|
||||||
void onUpdate(EntitiesData data)
|
void onUpdate(EntitiesData data)
|
||||||
{
|
|
||||||
/*if(move_vector.x == 0)
|
|
||||||
{
|
{
|
||||||
foreach(i; 0..data.length)
|
foreach(i; 0..data.length)
|
||||||
{
|
{
|
||||||
data.textures[i].coords = vec4(0*px,80*px,48*px,32*px);
|
data.velocity[i] += move_vector * launcher.deltaTime * 0.005;
|
||||||
}
|
|
||||||
//return;
|
|
||||||
}*/
|
|
||||||
//move every entity using movement vector
|
|
||||||
//if(move_vector.x != 0 || move_vector.y != 0)
|
|
||||||
foreach(i; 0..data.length)
|
|
||||||
{
|
|
||||||
data.velocity[i] += move_vector * launcher.delta_time * 0.005;
|
|
||||||
if(data.velocity[i].x > 0.5)data.velocity[i].x = 0.5;
|
if(data.velocity[i].x > 0.5)data.velocity[i].x = 0.5;
|
||||||
else if(data.velocity[i].x < -0.5)data.velocity[i].x = -0.5;
|
else if(data.velocity[i].x < -0.5)data.velocity[i].x = -0.5;
|
||||||
if(data.velocity[i].y > 0.5)data.velocity[i].y = 0.5;
|
if(data.velocity[i].y > 0.5)data.velocity[i].y = 0.5;
|
||||||
else if(data.velocity[i].y < -0.5)data.velocity[i].y = -0.5;
|
else if(data.velocity[i].y < -0.5)data.velocity[i].y = -0.5;
|
||||||
//data.locations[i].x += move_vector.x * launcher.delta_time * 0.25;
|
}
|
||||||
//data.locations[i].y += move_vector.y * launcher.delta_time * 0.25;
|
|
||||||
//if(move_vector.x > 0)data.textures[i].coords = vec4(48*px,80*px,48*px,32*px);
|
|
||||||
//else data.textures[i].coords = vec4(0*px,80*px,48*px,32*px);
|
|
||||||
}
|
|
||||||
/*else
|
|
||||||
foreach(i; 0..data.length)
|
|
||||||
{
|
|
||||||
data.velocity[i] = vec2(0,0);
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -3,11 +3,8 @@ module game_core.job_updater;
|
||||||
import bubel.ecs.std;
|
import bubel.ecs.std;
|
||||||
import bubel.ecs.vector;
|
import bubel.ecs.vector;
|
||||||
import bubel.ecs.atomic;
|
import bubel.ecs.atomic;
|
||||||
|
|
||||||
import ecs_utils.utils;
|
|
||||||
|
|
||||||
//import core.time;
|
|
||||||
import bubel.ecs.manager;
|
import bubel.ecs.manager;
|
||||||
|
|
||||||
import mmutils.thread_pool;
|
import mmutils.thread_pool;
|
||||||
|
|
||||||
version(LDC)
|
version(LDC)
|
||||||
|
|
@ -21,8 +18,6 @@ else
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//import supre.core.call_graph_generator;
|
|
||||||
|
|
||||||
struct ECSJobUpdater
|
struct ECSJobUpdater
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
@ -33,30 +28,15 @@ struct ECSJobUpdater
|
||||||
|
|
||||||
~this()
|
~this()
|
||||||
{
|
{
|
||||||
|
//wait for end of jobs
|
||||||
pool.waitThreads();
|
pool.waitThreads();
|
||||||
//pool.unregistExternalThread(thread_data);
|
//dispose jobs array
|
||||||
if(jobs)Mallocator.dispose(jobs);
|
if(jobs)Mallocator.dispose(jobs);
|
||||||
|
//free TLS data
|
||||||
version(WebAssembly)pthread_key_delete(tls_key);
|
version(WebAssembly)pthread_key_delete(tls_key);
|
||||||
else version(Android)pthread_key_delete(tls_key);
|
else version(Android)pthread_key_delete(tls_key);
|
||||||
}
|
}
|
||||||
|
|
||||||
version(WebAssembly)
|
|
||||||
{
|
|
||||||
__gshared pthread_key_t tls_key;
|
|
||||||
}
|
|
||||||
else version(Android)
|
|
||||||
{
|
|
||||||
__gshared pthread_key_t tls_key;
|
|
||||||
}
|
|
||||||
else static uint thread_id = 0;
|
|
||||||
|
|
||||||
ThreadPool pool;
|
|
||||||
ThreadData* thread_data;
|
|
||||||
|
|
||||||
int job_id = 0;
|
|
||||||
int no_dep_count = 0;
|
|
||||||
//static uint thread_id = 0;
|
|
||||||
|
|
||||||
struct Group
|
struct Group
|
||||||
{
|
{
|
||||||
~this() nothrow
|
~this() nothrow
|
||||||
|
|
@ -65,33 +45,40 @@ struct ECSJobUpdater
|
||||||
}
|
}
|
||||||
|
|
||||||
JobsGroup group;
|
JobsGroup group;
|
||||||
JobData[1024] jobs;
|
//each group can have up to 128 jobs
|
||||||
JobCaller[1024] callers;
|
JobData[128] jobs;
|
||||||
|
JobCaller[128] callers;
|
||||||
uint count = 0;
|
uint count = 0;
|
||||||
string name;
|
string name;
|
||||||
|
|
||||||
|
//mmutils.ThreadPool uses system of dependency where dependencies are added for child groups.
|
||||||
|
//Parent group has atomic counter and after completition it will add job groups dependant on it.
|
||||||
void dependantOn(Group* dependency)
|
void dependantOn(Group* dependency)
|
||||||
{
|
{
|
||||||
group.dependantOn(&dependency.group);
|
group.dependantOn(&dependency.group);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//add group to pool
|
||||||
void start()
|
void start()
|
||||||
{
|
{
|
||||||
group.thPool.addGroupAsynchronous(&group);
|
group.thPool.addGroupAsynchronous(&group);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//add jobs slice to group structure
|
||||||
void build(ThreadPool* pool)
|
void build(ThreadPool* pool)
|
||||||
{
|
{
|
||||||
group.thPool = pool;
|
group.thPool = pool;
|
||||||
group.jobs = jobs[0..count];
|
group.jobs = jobs[0..count];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//clear jobs
|
||||||
void clear()
|
void clear()
|
||||||
{
|
{
|
||||||
group = JobsGroup("name",null);
|
group = JobsGroup("name",null);
|
||||||
count = 0;
|
count = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//add single job to group
|
||||||
void add(JobCaller caller)
|
void add(JobCaller caller)
|
||||||
{
|
{
|
||||||
callers[count] = caller;
|
callers[count] = caller;
|
||||||
|
|
@ -100,15 +87,10 @@ struct ECSJobUpdater
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Group[] jobs;
|
//initialize thread pool and data
|
||||||
Vector!(Group*) call_jobs;
|
|
||||||
Group last_job;
|
|
||||||
JobData[1] groupEndJobs;
|
|
||||||
|
|
||||||
//TrackData[32] trackers;
|
|
||||||
|
|
||||||
void onCreate(uint threads_count)
|
void onCreate(uint threads_count)
|
||||||
{
|
{
|
||||||
|
//create TLS for Android and WebAsssembly
|
||||||
version(WebAssembly)pthread_key_create(&tls_key, null);
|
version(WebAssembly)pthread_key_create(&tls_key, null);
|
||||||
else version(Android)pthread_key_create(&tls_key, null);
|
else version(Android)pthread_key_create(&tls_key, null);
|
||||||
|
|
||||||
|
|
@ -119,6 +101,7 @@ struct ECSJobUpdater
|
||||||
jobs = Mallocator.makeArray!Group(256);
|
jobs = Mallocator.makeArray!Group(256);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//this function are providingn ThreadID to ECS. BubelECS is expecting ThreadID to be linear ID in range (0;ThreadsCount)
|
||||||
uint getThreadID() @nogc nothrow
|
uint getThreadID() @nogc nothrow
|
||||||
{
|
{
|
||||||
version(WebAssembly)return cast(int)pthread_getspecific(tls_key);
|
version(WebAssembly)return cast(int)pthread_getspecific(tls_key);
|
||||||
|
|
@ -126,9 +109,9 @@ struct ECSJobUpdater
|
||||||
else return thread_id;
|
else return thread_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//clear jobs data
|
||||||
void begin()
|
void begin()
|
||||||
{
|
{
|
||||||
job_id = 0;
|
|
||||||
call_jobs.clear();
|
call_jobs.clear();
|
||||||
|
|
||||||
foreach(ref job;jobs)
|
foreach(ref job;jobs)
|
||||||
|
|
@ -139,68 +122,57 @@ struct ECSJobUpdater
|
||||||
last_job.clear();
|
last_job.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void clearTracker()
|
//execute jobs
|
||||||
{
|
|
||||||
//foreach(ref tracker;trackers)tracker.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
@optStrategy("none")
|
|
||||||
void nop()
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
//@optStrategy("none")
|
|
||||||
void call()
|
void call()
|
||||||
{
|
{
|
||||||
|
//if there is no work return
|
||||||
if(last_job.group.getDependenciesWaitCount() == 0)return;
|
if(last_job.group.getDependenciesWaitCount() == 0)return;
|
||||||
if(call_jobs.length == 0)return;
|
if(call_jobs.length == 0)return;
|
||||||
|
|
||||||
//JobData[1] groupEndJobs;
|
//set last job
|
||||||
groupEndJobs[0] = JobData(&releaseMainThread, "Stop Threads", null, null);
|
groupEndJobs[0] = JobData(&releaseMainThread, "Stop Threads", null, null);
|
||||||
|
|
||||||
|
//add job to group
|
||||||
last_job.group.jobs = groupEndJobs;
|
last_job.group.jobs = groupEndJobs;
|
||||||
|
//set thread pool pointer
|
||||||
last_job.group.thPool = &pool;
|
last_job.group.thPool = &pool;
|
||||||
|
//last job should be called on main thread. It prevent some issues with death loops.
|
||||||
last_job.group.executeOnThreadNum = 0;
|
last_job.group.executeOnThreadNum = 0;
|
||||||
|
|
||||||
|
//start jobs without dependencies
|
||||||
foreach(job;call_jobs)
|
foreach(job;call_jobs)
|
||||||
{
|
{
|
||||||
job.start();
|
job.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*while(atomicLoad(ret) == 1)//!cas(&ret,0,1))
|
//add main thread to pool. It will be released in last job.
|
||||||
{
|
|
||||||
nop();
|
|
||||||
version(WebAssembly)//emscripten_main_thread_process_queued_calls();
|
|
||||||
}//*/
|
|
||||||
|
|
||||||
thread_data.threadStartFunc();
|
thread_data.threadStartFunc();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//callback that will release main thread
|
||||||
void releaseMainThread(ThreadData* th_data, JobData* data)
|
void releaseMainThread(ThreadData* th_data, JobData* data)
|
||||||
{
|
{
|
||||||
//atomicStore(ret,0);
|
|
||||||
pool.releaseExternalThreads();
|
pool.releaseExternalThreads();
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct JobCaller
|
static struct JobCaller
|
||||||
{
|
{
|
||||||
|
//ECS job
|
||||||
EntityManager.Job* job;
|
EntityManager.Job* job;
|
||||||
|
//pointer to parent
|
||||||
ECSJobUpdater* updater;
|
ECSJobUpdater* updater;
|
||||||
|
//job ID
|
||||||
uint id;
|
uint id;
|
||||||
|
|
||||||
|
//called by external thread
|
||||||
void callJob(ThreadData* th_data, JobData* data)
|
void callJob(ThreadData* th_data, JobData* data)
|
||||||
{
|
{
|
||||||
|
|
||||||
//uint job_id = updater.getThreadID();
|
|
||||||
//updater.trackers[job_id].begin(id);
|
|
||||||
version(WebAssembly)
|
version(WebAssembly)
|
||||||
{
|
{
|
||||||
//updater.thread_id = th_data.threadId;
|
|
||||||
pthread_setspecific(tls_key, cast(void*)th_data.threadId);
|
pthread_setspecific(tls_key, cast(void*)th_data.threadId);
|
||||||
if(th_data.threadId == 0)
|
if(th_data.threadId == 0)
|
||||||
{
|
{
|
||||||
|
//this emscripten call is required to make multithreading working
|
||||||
emscripten_main_thread_process_queued_calls();
|
emscripten_main_thread_process_queued_calls();
|
||||||
job.execute();
|
job.execute();
|
||||||
emscripten_main_thread_process_queued_calls();
|
emscripten_main_thread_process_queued_calls();
|
||||||
|
|
@ -214,23 +186,27 @@ struct ECSJobUpdater
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
//set thread id
|
||||||
updater.thread_id = th_data.threadId;
|
updater.thread_id = th_data.threadId;
|
||||||
|
//execture job. It's the function from BubelECS
|
||||||
job.execute();
|
job.execute();
|
||||||
}
|
}
|
||||||
//atomicOp!"-="(updater.jobs_count,1);
|
|
||||||
//updater.trackers[job_id].end();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//this is callback passed to EntityManager. EntityManager will call this for every jobs group. Every system will generate one group.
|
||||||
void dispatch(EntityManager.JobGroup group)
|
void dispatch(EntityManager.JobGroup group)
|
||||||
{
|
{
|
||||||
|
//check if group isn't empty
|
||||||
if(group.jobs.length == 0)
|
if(group.jobs.length == 0)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//add name for job. Used for traces.
|
||||||
jobs[group.id].name = cast(string)group.caller.system.name;
|
jobs[group.id].name = cast(string)group.caller.system.name;
|
||||||
|
|
||||||
|
//add jobs to group
|
||||||
foreach(ref job;group.jobs)
|
foreach(ref job;group.jobs)
|
||||||
{
|
{
|
||||||
uint index = 0;
|
uint index = 0;
|
||||||
|
|
@ -242,21 +218,51 @@ struct ECSJobUpdater
|
||||||
jobs[group.id].add(caller);
|
jobs[group.id].add(caller);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//build group
|
||||||
jobs[group.id].build(&pool);
|
jobs[group.id].build(&pool);
|
||||||
|
|
||||||
uint deps = cast(uint)group.dependencies.length;
|
uint deps = cast(uint)group.dependencies.length;
|
||||||
|
|
||||||
|
//add dependencies
|
||||||
foreach(dep;group.dependencies)
|
foreach(dep;group.dependencies)
|
||||||
{
|
{
|
||||||
if(jobs[dep.id].count && dep.caller.system.willExecute && dep.caller.system.enabled)jobs[group.id].dependantOn(&jobs[dep.id]);
|
if(jobs[dep.id].count && dep.caller.system.willExecute && dep.caller.system.enabled)jobs[group.id].dependantOn(&jobs[dep.id]);
|
||||||
else deps--;
|
else deps--;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//set as job without dependencies if it hasn't any
|
||||||
if(deps == 0)
|
if(deps == 0)
|
||||||
{
|
{
|
||||||
call_jobs.add(&jobs[group.id]);
|
call_jobs.add(&jobs[group.id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//last job is dependant on all jobs so it will be called after everything will be finished
|
||||||
last_job.dependantOn(&jobs[group.id]);
|
last_job.dependantOn(&jobs[group.id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Webassembly version works properly only when there is no thread local data (static variables).
|
||||||
|
//Because of that I'm using pthread tls instead of D. TLS is used only for storing ThreadID
|
||||||
|
version(WebAssembly)
|
||||||
|
{
|
||||||
|
__gshared pthread_key_t tls_key;
|
||||||
|
}
|
||||||
|
else version(Android)
|
||||||
|
{
|
||||||
|
__gshared pthread_key_t tls_key;
|
||||||
|
}
|
||||||
|
else static uint thread_id = 0;
|
||||||
|
|
||||||
|
//thread pool
|
||||||
|
ThreadPool pool;
|
||||||
|
//thread data used for main thread
|
||||||
|
ThreadData* thread_data;
|
||||||
|
|
||||||
|
//array of jobs
|
||||||
|
Group[] jobs;
|
||||||
|
//list of jobs which should be called on frame start as they have no dependencies
|
||||||
|
Vector!(Group*) call_jobs;
|
||||||
|
//last job group is used for releasing main thread from pool
|
||||||
|
Group last_job;
|
||||||
|
//last_job group has one job
|
||||||
|
JobData[1] groupEndJobs;
|
||||||
}
|
}
|
||||||
|
|
@ -58,7 +58,7 @@ struct GUIManager
|
||||||
{
|
{
|
||||||
foreach(tmpl; templates)
|
foreach(tmpl; templates)
|
||||||
{
|
{
|
||||||
launcher.manager.freeTemplate(tmpl.tmpl);
|
gEntityManager.freeTemplate(tmpl.tmpl);
|
||||||
}
|
}
|
||||||
foreach(comp; components)
|
foreach(comp; components)
|
||||||
{
|
{
|
||||||
|
|
@ -102,14 +102,14 @@ struct GUIManager
|
||||||
{
|
{
|
||||||
if(sys.id == id)return;
|
if(sys.id == id)return;
|
||||||
}
|
}
|
||||||
System* system = launcher.manager.getSystem(id);
|
System* system = gEntityManager.getSystem(id);
|
||||||
//const (char)* name =
|
//const (char)* name =
|
||||||
systems.add(SystemGUI(name,id,enabled));
|
systems.add(SystemGUI(name,id,enabled));
|
||||||
}
|
}
|
||||||
|
|
||||||
void addTemplate(ushort[] components, const (char)* name)
|
void addTemplate(ushort[] components, const (char)* name)
|
||||||
{
|
{
|
||||||
templates.add(TemplateGUI(name, launcher.manager.allocateTemplate(components)));
|
templates.add(TemplateGUI(name, gEntityManager.allocateTemplate(components)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void addTemplate(EntityTemplate* tmpl, const (char)* name)
|
void addTemplate(EntityTemplate* tmpl, const (char)* name)
|
||||||
|
|
@ -258,7 +258,7 @@ struct GUIManager
|
||||||
{
|
{
|
||||||
if(igCheckbox(system.name,&system.enabled))
|
if(igCheckbox(system.name,&system.enabled))
|
||||||
{
|
{
|
||||||
System* sys = launcher.manager.getSystem(system.id);
|
System* sys = gEntityManager.getSystem(system.id);
|
||||||
if(system.enabled)sys.enable();
|
if(system.enabled)sys.enable();
|
||||||
else sys.disable();
|
else sys.disable();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue