-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
|
|
@ -13,33 +13,39 @@ import app : launcher;
|
|||
|
||||
import bindbc.sdl;
|
||||
|
||||
//position component
|
||||
struct CLocation
|
||||
{
|
||||
//adds some extra functionality. Not required. Will be probably removed from library in the future.
|
||||
mixin ECS.Component;
|
||||
|
||||
alias value this;
|
||||
alias value this;//use component as it value
|
||||
|
||||
//default values work properly
|
||||
vec2 value = vec2(0);
|
||||
}
|
||||
|
||||
//scale component
|
||||
struct CScale
|
||||
{
|
||||
mixin ECS.Component;
|
||||
|
||||
alias value this;///use component as it value
|
||||
alias value this;//use component as it value
|
||||
|
||||
vec2 value = vec2(16,16);
|
||||
}
|
||||
|
||||
//rotation component
|
||||
struct CRotation
|
||||
{
|
||||
mixin ECS.Component;
|
||||
|
||||
alias value this;///use component as it value
|
||||
alias value this;//use component as it value
|
||||
|
||||
float value = 0;
|
||||
}
|
||||
|
||||
//depth component. Entity with higher depth will be rendered on top
|
||||
struct CDepth
|
||||
{
|
||||
mixin ECS.Component;
|
||||
|
|
@ -49,6 +55,7 @@ struct CDepth
|
|||
short value;
|
||||
}
|
||||
|
||||
//color component
|
||||
struct CColor
|
||||
{
|
||||
mixin ECS.Component;
|
||||
|
|
@ -58,6 +65,7 @@ struct CColor
|
|||
@GUIColor uint value;
|
||||
}
|
||||
|
||||
//component used for selection
|
||||
struct CSelected
|
||||
{
|
||||
mixin ECS.Component;
|
||||
|
|
@ -65,11 +73,13 @@ struct CSelected
|
|||
bool value = false;
|
||||
}
|
||||
|
||||
//component indicating that entity should receive input from mouse, keyboard, etc.
|
||||
struct CInput
|
||||
{
|
||||
mixin ECS.Component;
|
||||
}
|
||||
|
||||
//component with damping value
|
||||
struct CDamping
|
||||
{
|
||||
mixin ECS.Component;
|
||||
|
|
@ -79,6 +89,7 @@ struct CDamping
|
|||
@GUIRange(0,9) byte value = 1;
|
||||
}
|
||||
|
||||
//velocity component
|
||||
struct CVelocity
|
||||
{
|
||||
mixin ECS.Component;
|
||||
|
|
@ -88,6 +99,7 @@ struct CVelocity
|
|||
vec2 value = vec2(0,0);
|
||||
}
|
||||
|
||||
//factor which is used for velocity masking
|
||||
struct CVelocityFactor
|
||||
{
|
||||
mixin ECS.Component;
|
||||
|
|
@ -97,30 +109,35 @@ struct CVelocityFactor
|
|||
vec2 value = vec2(1);
|
||||
}
|
||||
|
||||
//flag indicating that entity is static and shouldn't be updated by most systems in every frame
|
||||
struct CStatic
|
||||
{
|
||||
mixin ECS.Component;
|
||||
}
|
||||
|
||||
//system which slowing down entities
|
||||
struct DampingSystem
|
||||
{
|
||||
//system will generate up to 32 jobs
|
||||
mixin ECS.System!32;
|
||||
|
||||
struct EntitiesData
|
||||
{
|
||||
uint length;
|
||||
const (Entity)[] entity;
|
||||
@readonly CDamping[] damping;
|
||||
CVelocity[] velocity;
|
||||
const (Entity)[] entity; //entity is readonly
|
||||
@readonly CDamping[] damping;//damping is readonly. Marking with @readonly will help multithreading algorithm
|
||||
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;
|
||||
|
||||
bool onBegin()
|
||||
{
|
||||
//calculate damping values
|
||||
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;
|
||||
|
|
@ -130,11 +147,13 @@ struct DampingSystem
|
|||
{
|
||||
foreach(i; 0..data.length)
|
||||
{
|
||||
//constantly slow down entity
|
||||
data.velocity[i] = data.velocity[i] * damp[data.damping[i]];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//system used for entity movement
|
||||
struct MoveSystem
|
||||
{
|
||||
mixin ECS.System!64;
|
||||
|
|
@ -144,23 +163,24 @@ struct MoveSystem
|
|||
uint length;
|
||||
CLocation[] location;
|
||||
@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)
|
||||
{
|
||||
//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)
|
||||
{
|
||||
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
|
||||
{
|
||||
foreach(i; 0..data.length)
|
||||
{
|
||||
data.location[i] += data.velocity[i] * launcher.delta_time;
|
||||
data.location[i] += data.velocity[i] * launcher.deltaTime;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -228,32 +248,13 @@ struct InputMovementSystem
|
|||
*/
|
||||
void onUpdate(EntitiesData data)
|
||||
{
|
||||
/*if(move_vector.x == 0)
|
||||
{
|
||||
foreach(i; 0..data.length)
|
||||
{
|
||||
data.textures[i].coords = vec4(0*px,80*px,48*px,32*px);
|
||||
}
|
||||
//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;
|
||||
data.velocity[i] += move_vector * launcher.deltaTime * 0.005;
|
||||
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;
|
||||
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);
|
||||
}*/
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue