-fixed sp,e demos issues and crashes

This commit is contained in:
Mergul 2021-03-06 23:39:43 +01:00
parent fa0c196c60
commit 2107f3908c
9 changed files with 100 additions and 42 deletions

View file

@ -58,7 +58,7 @@ struct CBall
{
mixin ECS.Component;
ubyte radius;
//ubyte radius;
}
struct CHitPoints
@ -394,12 +394,15 @@ void brickBreakerStart()
launcher.gui_manager.addComponent(CTexCoords(), "Tex Coords");
launcher.gui_manager.addComponent(CTexCoordsIndex(), "Tex Coords Index");
launcher.gui_manager.addComponent(CVelocity(), "Velocity");
launcher.gui_manager.addComponent(CInput(), "Velocity");
launcher.gui_manager.addComponent(CInput(), "Input");
launcher.gui_manager.addComponent(CPaddle(), "Paddle");
launcher.gui_manager.addComponent(CDamping(), "Damping");
launcher.gui_manager.addComponent(CBall(), "Ball");
launcher.gui_manager.addComponent(CBVH(), "BVH");
launcher.gui_manager.addComponent(CAABB(), "AABB");
launcher.gui_manager.addComponent(CStatic(), "Static Flag");
launcher.gui_manager.addComponent(CVelocityFactor(), "Velocity Factor");
launcher.gui_manager.addComponent(CHitPoints(), "Hit Points");
launcher.gui_manager.addSystem(becsID!MoveSystem, "Move System");
launcher.gui_manager.addSystem(becsID!EdgeCollisionSystem, "Edge Collision System");

View file

@ -402,12 +402,20 @@ void particlesStart()
launcher.gui_manager.addSystem(becsID!MouseAttractSystem,"Mouse Attract System");
launcher.gui_manager.addSystem(becsID!DampingSystem,"Damping System");
launcher.gui_manager.addSystem(becsID!ParticleLifeSystem,"Particle Life System");
launcher.gui_manager.addSystem(becsID!GravitySystem,"Gravity System");
// launcher.gui_manager.addComponent(CColor(),"Color (white)");
// launcher.gui_manager.addComponent(CColor(0xFF101540),"Color (red)");
// launcher.gui_manager.addComponent(CColor(0xFF251010),"Color (blue)");
// launcher.gui_manager.addComponent(CColor(0xFF102010),"Color (green)");
launcher.gui_manager.addComponent(CColor(0xFF101540),"Color");
launcher.gui_manager.addComponent(CLocation(),"Location");
launcher.gui_manager.addComponent(CScale(),"Scale");
launcher.gui_manager.addComponent(CTexCoords(),"Texture Coords");
launcher.gui_manager.addComponent(CTexCoordsIndex(),"Texture Coords Index");
launcher.gui_manager.addComponent(CRotation(),"Rotation");
launcher.gui_manager.addComponent(CDepth(),"Depth");
launcher.gui_manager.addComponent(CMaterialIndex(),"Material ID");
launcher.gui_manager.addComponent(CVelocityFactor(),"Velocity Factor");
launcher.gui_manager.addComponent(CAttractor(0.1),"Attractor");
launcher.gui_manager.addComponent(CForceRange(vec2(5,40)),"ForceRange");
launcher.gui_manager.addComponent(CVelocity(),"Velocity");

View file

@ -19,6 +19,7 @@ import ecs_utils.utils;
import game_core.basic;
import gui.attributes;
//import std.array : staticArray;
enum float px = 1.0/512.0;
@ -133,7 +134,7 @@ struct CAnimation
mixin ECS.Component;
vec4[] frames;
float time = 0;
@GUIRangeF(0,float.max)float time = 0;
}
//CIlocation is integer location used as grid cell coordination
@ -203,7 +204,7 @@ struct CSnake
}
Parts parts;
CMovement.Direction direction;
@GUIRange(0,3)CMovement.Direction direction;
}
//flag for apple
@ -241,7 +242,7 @@ struct CMovement
right
}
Direction direction;
@GUIRange(0,3)Direction direction;
}
// struct CInput
@ -373,8 +374,10 @@ struct AnimationRenderSystem
draw_data.depth = -1;
foreach(i;0..data.length)
{
uint frame = cast(uint)(data.animation[i].time);
if(frame >= data.animation[i].frames.length)frame = cast(uint)data.animation[i].frames.length - 1;
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[frame];
launcher.renderer.draw(draw_data);
}
}
@ -910,8 +913,9 @@ void snakeStart()
launcher.gui_manager.addComponent(CParticleVector(vec2(0,1)),"Particle Vector");
launcher.gui_manager.addComponent(CInput(),"Input");
launcher.gui_manager.addComponent(CMovement(CMovement.Direction.up),"Movement");
//launcher.gui_manager.addComponent(CAnimation(),"Movement");
launcher.gui_manager.addComponent(CAnimation(),"Animation");
launcher.gui_manager.addComponent(CILocation(),"Int Location");
launcher.gui_manager.addComponent(CLocation(),"Location");
launcher.gui_manager.addSystem(becsID!MoveSystem,"Move System");
launcher.gui_manager.addSystem(becsID!InputSystem,"Input System");
@ -922,6 +926,9 @@ void snakeStart()
launcher.gui_manager.addSystem(becsID!ParticleMovementSystem,"Particle Movement System");
launcher.gui_manager.addSystem(becsID!DrawAppleSystem,"Draw Apple System");
launcher.gui_manager.addSystem(becsID!DrawSnakeSystem,"Draw Snake System");
launcher.gui_manager.addSystem(becsID!CopyLocationSystem,"Copy Location System");
//launcher.gui_manager.addSystem(becsID!AppleSystem,"Apple System");
//launcher.gui_manager.addSystem(becsID!SnakeSystem,"Snake System");
snake.snake_destroy_particle_frames = Mallocator.makeArray([vec4(64,144,16,16)*px,vec4(80,144,16,16)*px,vec4(96,144,16,16)*px,vec4(112,144,16,16)*px].staticArray);

View file

@ -20,6 +20,8 @@ import game_core.basic;
import game_core.rendering;
import game_core.collision;
import gui.attributes;
private enum float px = 1.0/512.0;
@ -222,8 +224,8 @@ struct CWeapon
}
float shoot_time = 0;
Type type;
ubyte level = 1;
@GUIRange(0, 4) Type type;
@GUIRange(0, 11) ubyte level = 1;
}
struct CWeaponLocation
@ -237,7 +239,7 @@ struct CShootDirection
{
mixin ECS.Component;
Direction direction;
@GUIRange(0, 3) Direction direction;
}
struct CSideMove
@ -304,8 +306,8 @@ struct CAnimation
mixin ECS.Component;
vec4[] frames;
float time = 0;
float speed = 1;
@GUIRangeF(0, float.max)float time = 0;
@GUIRangeF(0, float.max)float speed = 1;
}
struct CAnimationLooped
@ -350,7 +352,7 @@ struct CParts
{
mixin ECS.Component;
ubyte count;
@GUIDisabled ubyte count;
}
struct CInit
@ -364,7 +366,7 @@ struct CInit
boss
}
Type type;
@GUIRange(0, 2)Type type;
}
struct CParticleEmitter
@ -373,9 +375,8 @@ struct CParticleEmitter
vec2 range = vec2(0,0);
vec2 time_range = vec2(500,1000);
///due to multithreading there should be separate template for every thread.
///It can be array of tempaltes or (like in this demo) simply index of template;
uint tmpl_id;
//uint tmpl_id;
//EntityTemplate* tmpl;
}
@ -404,7 +405,7 @@ struct CSpawnUponDeath
//EntityID parent;
//EntityTemplate* tmpl;
Type type;
@GUIRange(0,0) Type type;
}
///This component can be replaced by "CSpawnUponDeath" but I want to gives possibility to add this component to every entity
@ -413,7 +414,7 @@ struct CShootWaveUponDeath
{
mixin ECS.Component;
CWeapon.Type bullet_type;
@GUIRange(0, 4) CWeapon.Type bullet_type;
}
/*#######################################################################################################################
@ -1582,7 +1583,7 @@ struct PartsDestroySystem
becsID!CVelocity, becsID!CLocation, becsID!CParticleEmitter,
becsID!CParticleEmitterTime, becsID!CTargetParent, becsID!CDepth
].staticArray);
*flashes_emitter.getComponent!CParticleEmitter() = CParticleEmitter(vec2(0,0), vec2(800,1600), 0);
*flashes_emitter.getComponent!CParticleEmitter() = CParticleEmitter(vec2(0,0), vec2(800,1600));
}
void onDestroy()
@ -1783,7 +1784,8 @@ struct AnimationSystem
{
data.animation[i].time += dt * data.animation[i].speed;
while(cast(uint)data.animation[i].time >= data.animation[i].frames.length)data.animation[i].time -= cast(float)data.animation[i].frames.length;
if(cast(uint)(data.animation[i].time) >= data.animation[i].frames.length)assert(0);
//if(cast(uint)(data.animation[i].time) >= data.animation[i].frames.length)assert(0);
assert(cast(uint)(data.animation[i].time) < data.animation[i].frames.length);
uint index = cast(uint)(data.animation[i].time);
if(index < data.animation[i].frames.length)data.texcoords[i].value = data.animation[i].frames[index];
}
@ -2102,9 +2104,13 @@ void spaceInvadersStart()
draw_system.default_data.color = 0x80808080;
draw_system.default_data.texture = space_invaders.texture;
launcher.gui_manager.addComponent(CLocation(),"Location");
launcher.gui_manager.addComponent(CRotation(),"Rotation");
launcher.gui_manager.addComponent(CTexCoords(),"TexCoords");
launcher.gui_manager.addComponent(CInput(),"Input");
launcher.gui_manager.addComponent(CShip(),"Ship");
launcher.gui_manager.addComponent(CEnemy(),"Enemy");
launcher.gui_manager.addComponent(CShootDirection(),"Shoot Direction");
launcher.gui_manager.addComponent(CAutoShoot(),"Auto Shoot");
launcher.gui_manager.addComponent(CWeapon(0, CWeapon.Type.laser),"Weapon (laser)");
launcher.gui_manager.addComponent(CVelocity(vec2(0,0)),"Velocity (0,0)");
@ -2112,6 +2118,7 @@ void spaceInvadersStart()
launcher.gui_manager.addComponent(CSideMove(),"Side Move");
launcher.gui_manager.addComponent(CSideMove(0),"Side Move (g1)");
launcher.gui_manager.addComponent(CSideMove(1),"Side Move (g2)");
launcher.gui_manager.addComponent(CDepth(),"Depth");
launcher.gui_manager.addComponent(CShootGrid(),"Shoot Grid");
launcher.gui_manager.addComponent(CGuild(),"Guild (Player)");
launcher.gui_manager.addComponent(CGuild(1),"Guild (Enemy)");
@ -2119,24 +2126,29 @@ void spaceInvadersStart()
launcher.gui_manager.addComponent(CHitMark(),"Hit Mark");
launcher.gui_manager.addComponent(CUpgrade(CUpgrade.Upgrade.laser),"Upgrade (laser)");
launcher.gui_manager.addComponent(CParticle(1000),"Particle (1s)");
//launcher.gui_manager.addComponent(CMaxHitPoints(),"Max Hit Points");
launcher.gui_manager.addComponent(CMaxHitPoints(),"Max Hit Points");
launcher.gui_manager.addComponent(CAnimation(),"Animation");
launcher.gui_manager.addComponent(CDamping(0),"Damping (0)");
launcher.gui_manager.addComponent(CDamping(4),"Damping (4)");
launcher.gui_manager.addComponent(CDamping(8),"Damping (8)");
launcher.gui_manager.addComponent(CAnimationLooped(),"Animation loop flag");
launcher.gui_manager.addComponent(CTargetParent(),"Target Parent");
launcher.gui_manager.addComponent(CTargetPlayerShip(),"Target Player Ship");
launcher.gui_manager.addComponent(CTarget(),"Target");
launcher.gui_manager.addComponent(CChildren(),"Children");
launcher.gui_manager.addComponent(CVelocityFactor(),"Velocity Factor");
launcher.gui_manager.addComponent(CWeaponLocation(vec2(0,16)),"Weapon Location (0,16)");
launcher.gui_manager.addComponent(CInit(CInit.Type.space_ship),"Init (Ship)");
launcher.gui_manager.addComponent(CInit(CInit.Type.boss),"Init (Boss)");
launcher.gui_manager.addComponent(CInit(CInit.Type.tower),"Init (Tower)");
launcher.gui_manager.addComponent(CBoss(),"Boss");
launcher.gui_manager.addComponent(CParts(),"Parts");
launcher.gui_manager.addComponent(CColliderScale(),"Collider Scale");
launcher.gui_manager.addComponent(CParticleEmitter(),"Particle Emitter");
launcher.gui_manager.addComponent(CParticleEmitterTime(),"Particle Emitter Time");
//launcher.gui_manager.addComponent(CSpawnUponDeath(),"Spawn Upon Death");
launcher.gui_manager.addComponent(CSpawnUponDeath(),"Spawn Upon Death");
launcher.gui_manager.addComponent(CShootWaveUponDeath(CWeapon.Type.canon),"Wave Upon Death");
launcher.gui_manager.addComponent(CShootGridMask(),"Shoot grid mask");
launcher.gui_manager.addSystem(becsID!DrawSystem,"Draw System");
launcher.gui_manager.addSystem(becsID!InputMovementSystem,"Input Movement");
@ -2165,6 +2177,7 @@ void spaceInvadersStart()
launcher.gui_manager.addSystem(becsID!ChildDestroySystem,"Child Destroy System");
launcher.gui_manager.addSystem(becsID!ShootWaveSystem,"Shoot Wave System");
//launcher.gui_manager.addSystem(becsID!SpawnUponDeathSystem,"Child Destroy System");
//launcher.gui_manager.addSystem(becsID!CollisionMaskSystem,"Collision Mask");
//gEntityManager.getSystem(becsID!CleanSystem).disable();
{

View file

@ -11,6 +11,7 @@ import ecs_utils.utils;
import game_core.basic;
import gui.attributes;
void registerCollisionModule(EntityManager* manager)
{
@ -46,7 +47,7 @@ struct CBVH
{
mixin ECS.Component;
uint index;
@GUIDisabled uint index;
}
struct CAABB
@ -64,7 +65,7 @@ struct CShootGridMask
alias value this;
ubyte value;
@GUIDisabled ubyte value;
}
struct CColliderScale

View file

@ -4,17 +4,20 @@ enum GUIColor = "GUIColor";
struct GUIRange
{
union
struct
{
struct
{
int min;
int max;
}
struct
{
float minf;
float maxf;
}
int min;
int max;
}
}
}
struct GUIRangeF
{
struct
{
float minf;
float maxf;
}
}
enum GUIDisabled = "GUIDisabled";

View file

@ -54,6 +54,7 @@ struct VariableGUI
Type type;
const (char)* name;
ushort offset;
bool disabled = false;
union
{
Int int_;

View file

@ -152,6 +152,7 @@ struct GUIManager
//pragma(msg,member_type);
//pragma(msg,__traits(getMember, T, member).offsetof);
ushort offset = member.offsetof;//cast(ushort)__traits(getMember, T, member).offsetof;
static if(is(member_type == vec2))
{
comp_edit.variables[comp_edit.used++] = VariableGUI(VariableGUI.Type.vec2,member_str,offset);
@ -236,14 +237,20 @@ struct GUIManager
}
static if(hasUDA!(member,GUIRange))
{
comp_edit.variables[comp_edit.used-1].float_.min = getUDAs!(member,GUIRange)[0].minf;
comp_edit.variables[comp_edit.used-1].float_.max = getUDAs!(member,GUIRange)[1].maxf;
comp_edit.variables[comp_edit.used-1].float_.min = getUDAs!(member,GUIRange)[0].min;
comp_edit.variables[comp_edit.used-1].float_.max = getUDAs!(member,GUIRange)[0].max;
}
else static if(hasUDA!(member,GUIRangeF))
{
comp_edit.variables[comp_edit.used-1].float_.min = getUDAs!(member,GUIRangeF)[0].minf;
comp_edit.variables[comp_edit.used-1].float_.max = getUDAs!(member,GUIRangeF)[0].maxf;
}
else {
comp_edit.variables[comp_edit.used-1].float_.min = -float.max;
comp_edit.variables[comp_edit.used-1].float_.max = float.max;
}
}
static if(hasUDA!(member,GUIDisabled))comp_edit.variables[comp_edit.used - 1].disabled = true;
}
edit_components[becsID(comp)] = comp_edit;
}
@ -256,12 +263,14 @@ struct GUIManager
igIndent(8);
foreach(ref SystemGUI system;systems)
{
igPushIDPtr(&system);
if(igCheckbox(system.name,&system.enabled))
{
System* sys = gEntityManager.getSystem(system.id);
if(system.enabled)sys.enable();
else sys.disable();
}
igPopID();
}
igUnindent(8);
}
@ -337,13 +346,15 @@ struct GUIManager
{
vec4 color;
if(comp_id >= edit_components.length)return;
if(edit_components[comp_id].used)
//if(edit_components[comp_id].used)
if(edit_components[comp_id].name)
{
if(igCollapsingHeader(edit_components[comp_id].name, ImGuiTreeNodeFlags_SpanAvailWidth | ImGuiTreeNodeFlags_DefaultOpen))
{
igIndent(8);
foreach(ref VariableGUI var;edit_components[comp_id].variables[0 .. edit_components[comp_id].used])
{
igPushIDPtr(&var);
switch(var.type)
{
@ -351,7 +362,12 @@ struct GUIManager
igDragScalarClamp(var.name, ImGuiDataType_S8, data_ptr+var.offset, 0.1, cast(void*)&var.int_.min, cast(void*)&var.int_.max, null, 1);
break;
case VariableGUI.Type.ubyte_:
igDragScalarClamp(var.name, ImGuiDataType_U8, data_ptr+var.offset, 0.1, cast(void*)&var.int_.min, cast(void*)&var.int_.max, null, 1);
if(var.disabled)
{
ubyte v = *cast(ubyte*)(data_ptr+var.offset);
igDragScalarClamp(var.name, ImGuiDataType_U8, &v, 0.1, cast(void*)&var.int_.min, cast(void*)&var.int_.max, null, 1);
}
else igDragScalarClamp(var.name, ImGuiDataType_U8, data_ptr+var.offset, 0.1, cast(void*)&var.int_.min, cast(void*)&var.int_.max, null, 1);
break;
case VariableGUI.Type.short_:
igDragScalarClamp(var.name, ImGuiDataType_S16, data_ptr+var.offset, 0.1, cast(void*)&var.int_.min, cast(void*)&var.int_.max, null, 1);
@ -363,7 +379,12 @@ struct GUIManager
igDragScalarClamp(var.name, ImGuiDataType_S32, data_ptr+var.offset, 0.1, cast(void*)&var.int_.min, cast(void*)&var.int_.max, null, 1);
break;
case VariableGUI.Type.uint_:
igDragScalarClamp(var.name, ImGuiDataType_U32, data_ptr+var.offset, 0.1, cast(void*)&var.int_.min, cast(void*)&var.int_.max, null, 1);
if(var.disabled)
{
uint v = *cast(uint*)(data_ptr+var.offset);
igDragScalarClamp(var.name, ImGuiDataType_U32, &v, 0.1, cast(void*)&var.int_.min, cast(void*)&var.int_.max, null, 1);
}
else igDragScalarClamp(var.name, ImGuiDataType_U32, data_ptr+var.offset, 0.1, cast(void*)&var.int_.min, cast(void*)&var.int_.max, null, 1);
break;
case VariableGUI.Type.float_:
igDragScalarClamp(var.name, ImGuiDataType_Float, data_ptr+var.offset, 0.1, cast(void*)&var.float_.min, cast(void*)&var.float_.max, "%2.2f", 1);