-updated README.md
-fixed shaders for GL2 -added Entity selection tool -throw out tools from "Demo" window to "Tools" window -change ComboBox to Tabs for Tools -Added more verbose tips -Improved and fixed BrickBreaker collisions -fixed simple DUB issue
This commit is contained in:
parent
1acd0df0ef
commit
56f870bac6
21 changed files with 332 additions and 133 deletions
|
|
@ -75,6 +75,7 @@ struct Launcher
|
|||
double delta_time;
|
||||
uint fps;
|
||||
vec2 render_position;
|
||||
bool play = true;
|
||||
|
||||
Tool used_tool;
|
||||
int tool_size = 100;
|
||||
|
|
@ -85,6 +86,7 @@ struct Launcher
|
|||
bool tool_mode = true;
|
||||
ToolCircle* tool_circle;
|
||||
bool show_filtered;
|
||||
EntityID selected_entity;
|
||||
|
||||
bool swap_interval = true;
|
||||
|
||||
|
|
@ -95,6 +97,7 @@ struct Launcher
|
|||
bool show_stat_wnd = true;
|
||||
bool show_tips = true;
|
||||
bool show_demo_wnd = true;
|
||||
bool show_tools_wnd = true;
|
||||
bool show_virtual_keys_wnd = false;
|
||||
bool show_profile_wnd = true;
|
||||
|
||||
|
|
@ -110,10 +113,16 @@ struct Launcher
|
|||
float draw_time = 0;
|
||||
}
|
||||
|
||||
double deltaTime()
|
||||
{
|
||||
return delta_time * play;
|
||||
}
|
||||
|
||||
DemoCallbacks demo;
|
||||
|
||||
void switchDemo(DemoCallbacks callbacks)//void function() start, bool function() loop, void function() end, void function(SDL_Event*) event, const (char)* tips)
|
||||
{
|
||||
show_tips = true;
|
||||
gui_manager.clear();
|
||||
//launcher.ent
|
||||
|
||||
|
|
@ -164,6 +173,7 @@ struct Launcher
|
|||
ComponentRef[] add_comps;
|
||||
ushort[] rem_comps;
|
||||
ushort[] filter;
|
||||
float distance = float.max;
|
||||
|
||||
bool filterEntity(ref const Entity entity)
|
||||
{
|
||||
|
|
@ -222,6 +232,21 @@ struct Launcher
|
|||
if(length < size2)gEM.removeComponents(data.entity[i].id, rem_comps);
|
||||
}
|
||||
}
|
||||
|
||||
void selectEntity(IteratorSystem.EntitiesData data)
|
||||
{
|
||||
if(!filterEntity(data.entity[0]))return;
|
||||
foreach(i;0..data.length)
|
||||
{
|
||||
vec2 rel_vec = data.location[i] - position;
|
||||
float length = rel_vec.x * rel_vec.x + rel_vec.y * rel_vec.y;
|
||||
if(length < distance)
|
||||
{
|
||||
distance = length;
|
||||
launcher.selected_entity = data.entity[i].id;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
float half_size = tool_size * 0.5;
|
||||
|
|
@ -276,6 +301,10 @@ struct Launcher
|
|||
}
|
||||
}
|
||||
break;
|
||||
case Tool.selector:
|
||||
iterator.distance = size2;
|
||||
manager.callEntitiesFunction!IteratorSystem(&iterator.selectEntity);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
@ -717,12 +746,14 @@ void mainLoop(void* arg)
|
|||
|
||||
if(launcher.show_tips)
|
||||
{
|
||||
igSetNextWindowPos(ImVec2(launcher.window_size.x - 550, 80), ImGuiCond_Once, ImVec2(0,0));
|
||||
igSetNextWindowSize(ImVec2(300, 0), ImGuiCond_Once);
|
||||
igSetNextWindowBgAlpha(launcher.windows_alpha);
|
||||
igSetNextWindowPos(ImVec2(launcher.window_size.x /2 -250, 100), ImGuiCond_Once, ImVec2(0,0));
|
||||
igSetNextWindowSize(ImVec2(500, -1), ImGuiCond_Once);
|
||||
igSetNextWindowBgAlpha(0.95);
|
||||
if(igBegin("Tips",&launcher.show_tips,ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoSavedSettings))
|
||||
{
|
||||
// igBeginChild("",ImVec2(0,0),0,0);
|
||||
igTextWrapped(launcher.demo.tips);
|
||||
// igEndChild();
|
||||
}
|
||||
igEnd();
|
||||
}
|
||||
|
|
@ -730,9 +761,10 @@ void mainLoop(void* arg)
|
|||
if(launcher.show_demo_wnd)
|
||||
{
|
||||
igSetNextWindowPos(ImVec2(launcher.window_size.x - 260, 30), ImGuiCond_Once, ImVec2(0,0));
|
||||
igSetNextWindowSize(ImVec2(250, launcher.window_size.y - 60), ImGuiCond_Once);
|
||||
igSetNextWindowSize(ImVec2(250, 300), ImGuiCond_Once);
|
||||
if(igBegin("Demo",&launcher.show_demo_wnd,0))
|
||||
{
|
||||
igCheckbox("Play",&launcher.play);
|
||||
ImDrawList* draw_list = igGetWindowDrawList();
|
||||
igBeginGroup();
|
||||
launcher.gui_manager.gui();
|
||||
|
|
@ -742,11 +774,11 @@ void mainLoop(void* arg)
|
|||
//ImDrawList_AddRect(draw_list, igGetItemRectMin(), igGetItemRectMax(), igColorConvertFloat4ToU32(ImVec4(0.4,0.4,0.4,0.4)), -1, 0, 1);
|
||||
//igBeginChildFrame(1,ImVec2(0,-1),ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_ChildWindow);
|
||||
//igBeginChild("Tool frame",ImVec2(-1,-1),true,0);
|
||||
igBeginGroup();
|
||||
if(igCollapsingHeader("Tool##ToolHeader", ImGuiTreeNodeFlags_SpanAvailWidth | ImGuiTreeNodeFlags_DefaultOpen))
|
||||
{
|
||||
igIndent(8);
|
||||
if(igBeginCombo("Tool",tool_strings[launcher.used_tool],0))
|
||||
// igBeginGroup();
|
||||
// if(igCollapsingHeader("Tool##ToolHeader", ImGuiTreeNodeFlags_SpanAvailWidth | ImGuiTreeNodeFlags_DefaultOpen))
|
||||
// {
|
||||
// igIndent(8);
|
||||
/*if(igBeginCombo("Tool",tool_strings[launcher.used_tool],0))
|
||||
{
|
||||
if(igSelectable("Entity spawner",false,0,ImVec2(0,0)))
|
||||
{
|
||||
|
|
@ -761,8 +793,48 @@ void mainLoop(void* arg)
|
|||
launcher.used_tool = Tool.selector;
|
||||
}
|
||||
igEndCombo();
|
||||
}*/
|
||||
/*if(igSelectable("Entity spawner",false,0,ImVec2(0,0)))
|
||||
{
|
||||
launcher.used_tool = Tool.entity_spawner;
|
||||
}
|
||||
if(igIsItemHovered(0))igSetTooltip("Select tool (CTRL + 1,2,3)");
|
||||
if(igSelectable("Component manipulator",false,0,ImVec2(0,0)))
|
||||
{
|
||||
launcher.used_tool = Tool.component_manipulator;
|
||||
}
|
||||
if(igSelectable("Selector",false,0,ImVec2(0,0)))
|
||||
{
|
||||
launcher.used_tool = Tool.selector;
|
||||
}*/
|
||||
/*if(igBeginTabBar("Tool",ImGuiTabBarFlags_NoCloseWithMiddleMouseButton))
|
||||
{
|
||||
if(igIsItemHovered(0))igSetTooltip("Select tool (CTRL + 1,2,3)");
|
||||
bool a = 1;
|
||||
//this is used as hack to make CTRL+1/2/3 tab selection possible
|
||||
static Tool prev_tool = Tool.entity_spawner;
|
||||
bool different = prev_tool != launcher.used_tool;
|
||||
Tool tool;
|
||||
if(igBeginTabItem("Entity spawner", &a, launcher.used_tool == Tool.entity_spawner && different ? ImGuiTabItemFlags_SetSelected : 0))
|
||||
{
|
||||
tool = Tool.entity_spawner;
|
||||
igEndTabItem();
|
||||
}
|
||||
if(igBeginTabItem("Component manipulator", &a, launcher.used_tool == Tool.component_manipulator && different ? ImGuiTabItemFlags_SetSelected : 0))
|
||||
{
|
||||
tool = Tool.component_manipulator;
|
||||
igEndTabItem();
|
||||
}
|
||||
if(igBeginTabItem("Selector", &a, launcher.used_tool == Tool.selector && different ? ImGuiTabItemFlags_SetSelected : 0))
|
||||
{
|
||||
tool = Tool.selector;
|
||||
igEndTabItem();
|
||||
}
|
||||
launcher.used_tool = tool;
|
||||
prev_tool = launcher.used_tool;
|
||||
}
|
||||
igEndTabBar();
|
||||
|
||||
|
||||
igCheckbox("Show Tool", &launcher.tool_show);
|
||||
if(igIsItemHovered(0))igSetTooltip("Show/hide graphical tool representation");
|
||||
igSameLine(0,4);
|
||||
|
|
@ -785,10 +857,11 @@ void mainLoop(void* arg)
|
|||
|
||||
igSliderInt("Tool size", &launcher.tool_size, 0, 256, null);
|
||||
igSliderFloat("Tool repeat", &launcher.tool_repeat, 0, 1024, null, 4);
|
||||
launcher.gui_manager.toolGui();
|
||||
igUnindent(8);
|
||||
}
|
||||
igEndGroup();
|
||||
launcher.gui_manager.toolGui();*/
|
||||
|
||||
// igUnindent(8);
|
||||
// }
|
||||
// igEndGroup();
|
||||
ImDrawList_AddRect(draw_list, igGetItemRectMin(), ImVec2(igGetWindowPos().x+igGetWindowWidth()-2,igGetItemRectMax().y), igColorConvertFloat4ToU32(ImVec4(0.4,0.4,0.4,0.4)), 2, ImDrawCornerFlags_All, 1);
|
||||
|
||||
//igBeginGroup();
|
||||
|
|
@ -813,6 +886,75 @@ void mainLoop(void* arg)
|
|||
igEnd();
|
||||
}
|
||||
|
||||
if(launcher.show_tools_wnd)
|
||||
{
|
||||
|
||||
igSetNextWindowPos(ImVec2(launcher.window_size.x - 300, 340), ImGuiCond_Once, ImVec2(0,0));
|
||||
igSetNextWindowSize(ImVec2(300, launcher.window_size.y - 370), ImGuiCond_Once);
|
||||
if(igBegin("Tools", &launcher.show_tools_wnd, ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse))
|
||||
{
|
||||
if(igIsItemHovered(0))igSetTooltip("Select tool (CTRL + 1,2,3)");
|
||||
|
||||
if(igBeginTabBar("Tool",ImGuiTabBarFlags_NoCloseWithMiddleMouseButton))
|
||||
{
|
||||
bool a = 1;
|
||||
//this is used as hack to make CTRL+1/2/3 tab selection possible
|
||||
static Tool prev_tool = Tool.entity_spawner;
|
||||
bool different = prev_tool != launcher.used_tool;
|
||||
Tool tool;
|
||||
if(igBeginTabItem("Entity spawner", &a, launcher.used_tool == Tool.entity_spawner && different ? ImGuiTabItemFlags_SetSelected : 0))
|
||||
{
|
||||
tool = Tool.entity_spawner;
|
||||
igEndTabItem();
|
||||
}
|
||||
if(igBeginTabItem("Component manipulator", &a, launcher.used_tool == Tool.component_manipulator && different ? ImGuiTabItemFlags_SetSelected : 0))
|
||||
{
|
||||
tool = Tool.component_manipulator;
|
||||
igEndTabItem();
|
||||
}
|
||||
if(igBeginTabItem("Selector", &a, launcher.used_tool == Tool.selector && different ? ImGuiTabItemFlags_SetSelected : 0))
|
||||
{
|
||||
tool = Tool.selector;
|
||||
igEndTabItem();
|
||||
}
|
||||
launcher.used_tool = tool;
|
||||
prev_tool = launcher.used_tool;
|
||||
}
|
||||
igEndTabBar();
|
||||
|
||||
|
||||
igCheckbox("Show Tool", &launcher.tool_show);
|
||||
if(igIsItemHovered(0))igSetTooltip("Show/hide graphical tool representation");
|
||||
igSameLine(0,4);
|
||||
igCheckbox("Show Filtered", &launcher.show_filtered);
|
||||
if(igIsItemHovered(0))igSetTooltip("Show/hide filtered entities");
|
||||
if(launcher.used_tool == Tool.component_manipulator)
|
||||
{
|
||||
igCheckbox("Override", &launcher.override_);
|
||||
}
|
||||
|
||||
//igSelectable("Selectabe",false,ImGuiSelectableFlags_None,ImVec2(0,0));
|
||||
if(launcher.used_tool != Tool.selector)
|
||||
{
|
||||
if(igRadioButtonBool("Add", launcher.tool_mode))launcher.tool_mode = true;
|
||||
if(igIsItemHovered(0))igSetTooltip("Tool should adding (Entities or components)");
|
||||
igSameLine(0,4);
|
||||
if(igRadioButtonBool("Remove", !launcher.tool_mode))launcher.tool_mode = false;
|
||||
if(igIsItemHovered(0))igSetTooltip("Tool should removing (Entities or components)");
|
||||
}
|
||||
|
||||
igSliderInt("Tool size", &launcher.tool_size, 0, 256, null);
|
||||
igSliderFloat("Tool repeat", &launcher.tool_repeat, 0, 1024, null, 4);
|
||||
|
||||
if(igBeginChild("",ImVec2(0,0),1,0))
|
||||
{
|
||||
launcher.gui_manager.toolGui();
|
||||
}
|
||||
igEndChild();
|
||||
}
|
||||
igEnd();
|
||||
}
|
||||
|
||||
if(launcher.show_profile_wnd)
|
||||
{
|
||||
//igSetNextWindowPos(ImVec2(launcher.window_size.x - 260, launcher.window_size.y - 280), ImGuiCond_Once, ImVec2(0,0));
|
||||
|
|
@ -864,10 +1006,20 @@ void mainLoop(void* arg)
|
|||
|
||||
double loop_time = launcher.getTime();
|
||||
launcher.job_updater.pool.tryWaitCount = 10000;
|
||||
if(launcher.demo.loop && !launcher.demo.loop())
|
||||
{
|
||||
quit();
|
||||
*cast(bool*)arg = false;
|
||||
if(launcher.play)
|
||||
{
|
||||
if(launcher.demo.loop && !launcher.demo.loop())
|
||||
{
|
||||
quit();
|
||||
*cast(bool*)arg = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
launcher.manager.begin();
|
||||
import game_core.rendering;
|
||||
launcher.manager.callEntitiesFunction!DrawSystem(&(launcher.manager.getSystem!DrawSystem).onUpdate);
|
||||
launcher.manager.end();
|
||||
}
|
||||
launcher.job_updater.pool.tryWaitCount = 0;
|
||||
|
||||
|
|
@ -1119,7 +1271,7 @@ int app_main(int argc, char** argv)
|
|||
// launcher.switchDemo(&simpleStart,&simpleLoop,&simpleEnd,&simpleEvent,Simple.tips);
|
||||
// launcher.switchDemo(getParticlesDemo());
|
||||
// launcher.switchDemo(getSimpleDemo());
|
||||
launcher.switchDemo(getBrickBreakerDemo());
|
||||
launcher.switchDemo(getSimpleDemo());
|
||||
}
|
||||
|
||||
int key_num;
|
||||
|
|
|
|||
|
|
@ -24,6 +24,13 @@ extern(C):
|
|||
|
||||
private enum float px = 1.0/512.0;
|
||||
|
||||
float clamp(float v, float min, float max)
|
||||
{
|
||||
if(v<min)return min;
|
||||
else if (v>max)return max;
|
||||
else return v;
|
||||
}
|
||||
|
||||
/*#######################################################################################################################
|
||||
------------------------------------------------ Components ------------------------------------------------------------------
|
||||
#######################################################################################################################*/
|
||||
|
|
@ -192,50 +199,32 @@ struct BallCollisionSystem
|
|||
CScale* scale = entity.getComponent!CScale;
|
||||
if(location && scale)
|
||||
{
|
||||
float radius = data.scale[i].x;
|
||||
float radius = data.scale[i].x*0.5;
|
||||
vec2 rel_pos = *location - data.location[i];
|
||||
vec2 abs_rel_pos = rel_pos;
|
||||
if(abs_rel_pos.x < 0)abs_rel_pos.x = -abs_rel_pos.x;
|
||||
if(abs_rel_pos.y < 0)abs_rel_pos.y = -abs_rel_pos.y;
|
||||
|
||||
vec2 half_scale = *scale * 0.25f;
|
||||
vec2 half_scale = *scale * 0.5f;
|
||||
|
||||
vec2 nearest_point;
|
||||
nearest_point.x = clamp(rel_pos.x, -half_scale.x, half_scale.x);
|
||||
nearest_point.y = clamp(rel_pos.y, -half_scale.y, half_scale.y);
|
||||
|
||||
if(abs_rel_pos.x < half_scale.x + radius &&
|
||||
abs_rel_pos.y < half_scale.y + radius)
|
||||
vec2 vector;
|
||||
if(nearest_point == rel_pos)
|
||||
{
|
||||
if(abs_rel_pos.x < half_scale.x)
|
||||
{
|
||||
if(rel_pos.y * data.velocity[i].y > 0)
|
||||
{
|
||||
data.velocity[i].y = -data.velocity[i].y;
|
||||
launcher.manager.sendEvent(id,EDamage(1));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if(abs_rel_pos.y < half_scale.y)
|
||||
{
|
||||
if(rel_pos.x * data.velocity[i].x > 0)
|
||||
{
|
||||
data.velocity[i].x = -data.velocity[i].x;
|
||||
launcher.manager.sendEvent(id,EDamage(1));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
vec2 vector = abs_rel_pos - half_scale;
|
||||
if(rel_pos.x > 0)vector.x = -vector.x;
|
||||
if(rel_pos.y > 0)vector.y = -vector.y;
|
||||
vector = nearest_point;
|
||||
radius = float.max;
|
||||
}
|
||||
else vector = nearest_point - rel_pos;
|
||||
float pow_dist = dot(vector, vector);
|
||||
|
||||
float pow_dist = vector.length2();
|
||||
if(pow_dist < radius*radius)
|
||||
{
|
||||
vector = vector / sqrtf(pow_dist);
|
||||
data.velocity[i] = data.velocity[i] - vector * (2 * dot(vector, data.velocity[i]));
|
||||
launcher.manager.sendEvent(id,EDamage(1));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if(dot(data.velocity[i], vector) > 0.01)return true;
|
||||
|
||||
if(pow_dist < radius*radius)
|
||||
{
|
||||
vector = vector / sqrtf(pow_dist);
|
||||
data.velocity[i] = data.velocity[i] - vector * (2 * dot(vector, data.velocity[i]));
|
||||
launcher.manager.sendEvent(id,EDamage(1));
|
||||
return cast(bool)(hits--);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -244,6 +233,7 @@ struct BallCollisionSystem
|
|||
|
||||
EntitiesData data;
|
||||
uint i;
|
||||
uint hits;
|
||||
}
|
||||
|
||||
ShootGrid* grid;
|
||||
|
|
@ -279,6 +269,7 @@ struct BallCollisionSystem
|
|||
foreach(i; 0..data.length)
|
||||
{
|
||||
state.i = i;
|
||||
state.hits = 1;
|
||||
//float radius = data.scale[i].x;
|
||||
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);
|
||||
|
|
@ -317,7 +308,10 @@ struct DamageSystem
|
|||
|
||||
struct BrickBreakerDemo
|
||||
{
|
||||
__gshared const (char)* tips = "Brick breaker demo. It's a game about destroying evil bricks.";
|
||||
__gshared const (char)* tips = "Brick breaker demo. It's a game about destroying evil bricks.
|
||||
|
||||
This demo is usnfinished yet but collision works well. Bricks can be destroyed. Spawning thousands of bricks and then thousands of balls is good way to try demo.
|
||||
Bricks uses StaticBVH, ball don't collide witch each other, paddle is added to dynamic BVH and collide with balls. But nothing keeps you from adding dynamic collision for balls.";
|
||||
|
||||
//EntityTemplate* tmpl;
|
||||
Texture texture;
|
||||
|
|
@ -418,6 +412,7 @@ void brickBreakerStart()
|
|||
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.addSystem(becsID!MoveSystem, "Move System");
|
||||
launcher.gui_manager.addSystem(becsID!EdgeCollisionSystem, "Edge Collision System");
|
||||
|
|
|
|||
|
|
@ -180,7 +180,7 @@ struct DrawSystem
|
|||
// {
|
||||
// foreach(i; 0..data.length)
|
||||
// {
|
||||
// data.locations[i] += data.velocity[i] * launcher.delta_time;
|
||||
// data.locations[i] += data.velocity[i] * launcher.deltaTime;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
|
@ -208,7 +208,7 @@ struct MouseAttractSystem
|
|||
|
||||
void onUpdate(EntitiesData data)
|
||||
{
|
||||
float speed = launcher.delta_time * 0.01;
|
||||
float speed = launcher.deltaTime * 0.01;
|
||||
foreach(i;0..data.length)
|
||||
{
|
||||
vec2 rel_pos = mouse_pos - data.locations[i];
|
||||
|
|
@ -236,7 +236,7 @@ struct AttractSystem
|
|||
|
||||
void onUpdate(AttractorIterator.EntitiesData adata)
|
||||
{
|
||||
float speed = launcher.delta_time * 0.00004;
|
||||
float speed = launcher.deltaTime * 0.00004;
|
||||
if(adata.vortex)
|
||||
{
|
||||
foreach(i;0..data.length)
|
||||
|
|
@ -365,7 +365,7 @@ struct PlayAreaSystem
|
|||
// {
|
||||
// foreach(i;0..10)
|
||||
// {
|
||||
// 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;
|
||||
|
|
@ -395,7 +395,7 @@ struct ParticleLifeSystem
|
|||
|
||||
bool onBegin()
|
||||
{
|
||||
delta_time = cast(int)(launcher.delta_time * 1000);
|
||||
delta_time = cast(int)(launcher.deltaTime * 1000);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -423,7 +423,7 @@ struct GravitySystem
|
|||
|
||||
void onUpdate(EntitiesData data)
|
||||
{
|
||||
float delta_time = launcher.delta_time * 0.00_092;
|
||||
float delta_time = launcher.deltaTime * 0.00_092;
|
||||
foreach(i; 0..data.length)
|
||||
{
|
||||
data.velocity[i].y -= delta_time;
|
||||
|
|
@ -437,7 +437,8 @@ struct GravitySystem
|
|||
|
||||
struct ParticlesDemo
|
||||
{
|
||||
__gshared const (char)* tips = "Use \"space\" to spwan entities.\n\nSystems can be enabled/disabled from \"Simple\" window.";
|
||||
__gshared const (char)* tips = "Particles by default have no velocity. You can spawn \"Attractor\" which attract particles, or \"Vortex\" which attracts and spin particles.
|
||||
Please do not spawn to many of them as every \"Attractor\" iterate over all particles (brute force).";
|
||||
|
||||
Texture texture;
|
||||
}
|
||||
|
|
@ -471,6 +472,7 @@ void particlesRegister()
|
|||
launcher.manager.registerComponent!CParticleLife;
|
||||
launcher.manager.registerComponent!CForceRange;
|
||||
launcher.manager.registerComponent!CMaterialIndex;
|
||||
launcher.manager.registerComponent!CVelocityFactor;
|
||||
|
||||
launcher.manager.registerSystem!MoveSystem(0);
|
||||
launcher.manager.registerSystem!DrawSystem(100);
|
||||
|
|
|
|||
|
|
@ -98,6 +98,7 @@ DemoCallbacks getSanboxDemo()
|
|||
demo.initialize = &sandboxStart;
|
||||
demo.deinitialize = &sandboxEnd;
|
||||
demo.loop = &sandboxLoop;
|
||||
demo.tips = "tips";
|
||||
demo.tips = "This demo contains all components, systems and events from previous demos. They was not designed for that kind of coexisting. Some system collide with other making some weird things.
|
||||
This gives biggest opportunities. You can add tower on top of snake, or lasers to paddle from BrickBreaker. This will be improved in next versions of ECS demo.";
|
||||
return demo;
|
||||
}
|
||||
|
|
@ -99,7 +99,32 @@ struct MoveSystem
|
|||
|
||||
struct Simple
|
||||
{
|
||||
__gshared const (char)* tips = "Use \"space\" to spwan entities.\n\nSystems can be enabled/disabled from \"Simple\" 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.
|
||||
Options:
|
||||
* Show Tool - enable/disable rendering of blue circle around cursor
|
||||
* Show Filtered - enable/disable higliting filtered entities. For \"Component manipulator\" tool it shows entities which has selected component.
|
||||
* Add/Remove - select primary action. LMB - primary action, RMB - secondary action
|
||||
* Tools size - size of tool
|
||||
* Tool repeat - how many times in one second tool should take action (e.g. 1000 means every second \"Entity spawner\" will spawn 1000 enties)
|
||||
* Override - enabled means that \"Component manipulator\" will override components data if entity already has that component
|
||||
Tools:
|
||||
* Entity spawner - used to spawn new entities
|
||||
* Component manipulator - used to add/remove components to/from entities
|
||||
* Selector - allow to select entity, show and modify his data. Only one entity can be selected, selector selects entity nearest co cursor.
|
||||
|
||||
ShortCuts:
|
||||
* CRTL*1/2/3 - change tool
|
||||
* Mouse wheel - change tool size
|
||||
* SHIFT + Mouse wheel - change entity/component in tool list
|
||||
* LBM - primary action (default: add entity / add component)
|
||||
* RMB - secondary action (default: remove entity / remove component)
|
||||
|
||||
\"Statistic\" windows shows FPS and entities count.
|
||||
|
||||
From top menu bar (upper left corner) you can select different demos or change some options. Multihtreading is highly recommended, but it can not working on mobile phones or Firefox browser.
|
||||
|
||||
Demo is capable rendering of hundreds of thousands of entities. Playable area is heavily too small to show that count of entities, but you can try it :)";
|
||||
|
||||
EntityTemplate* tmpl;
|
||||
Texture texture;
|
||||
|
|
@ -137,6 +162,9 @@ void simpleStart()
|
|||
launcher.gui_manager.addSystem(becsID!MoveSystem,"Move Up System");
|
||||
launcher.gui_manager.addSystem(becsID!DrawSystem,"Draw System");
|
||||
|
||||
launcher.gui_manager.addComponent(CLocation(), "Location");
|
||||
launcher.gui_manager.addComponent(CDrawDefault(), "DrawDefault");
|
||||
|
||||
simple.tmpl = launcher.manager.allocateTemplate([becsID!CLocation, becsID!CDrawDefault].staticArray);
|
||||
//*simple.tmpl.getComponent!CTexCoordsIndex = TexCoordsManager.instance.getCoordIndex(vec4(0,48,16,16)*px);
|
||||
//CLocation* loc_comp = simple.tmpl.getComponent!CLocation;
|
||||
|
|
|
|||
|
|
@ -58,7 +58,8 @@ enum SnakePart : ubyte
|
|||
|
||||
struct Snake
|
||||
{
|
||||
__gshared const (char)* tips = "Use \"WASD\" keys to move.";
|
||||
__gshared const (char)* tips = "Use \"WASD\" keys to move. If you loose you can always spawn new snake... or several snakes.
|
||||
This demo is an example that in ECS you can make very \"non-ECS\" game";
|
||||
|
||||
EntityTemplate* apple_tmpl;
|
||||
EntityTemplate* snake_tmpl;
|
||||
|
|
@ -286,7 +287,7 @@ struct ParticleSystem
|
|||
{
|
||||
foreach(i;0..data.length)
|
||||
{
|
||||
data.particle[i].life -= launcher.delta_time;
|
||||
data.particle[i].life -= launcher.deltaTime;
|
||||
if(data.particle[i].life < 0)launcher.manager.removeEntity(data.entities[i].id);
|
||||
}
|
||||
}
|
||||
|
|
@ -328,7 +329,7 @@ struct AnimationSystem
|
|||
{
|
||||
foreach(i;0..data.length)
|
||||
{
|
||||
data.animation[i].time += launcher.delta_time * 0.01;
|
||||
data.animation[i].time += launcher.deltaTime * 0.01;
|
||||
while(data.animation[i].time >= data.animation[i].frames.length)data.animation[i].time -= cast(float)data.animation[i].frames.length;
|
||||
}
|
||||
}
|
||||
|
|
@ -971,7 +972,7 @@ bool snakeLoop()
|
|||
|
||||
launcher.manager.begin();
|
||||
|
||||
float delta_time = launcher.delta_time;
|
||||
float delta_time = launcher.deltaTime;
|
||||
if(delta_time > 2000)delta_time = 2000;
|
||||
__gshared float time = 0;
|
||||
|
||||
|
|
|
|||
|
|
@ -36,7 +36,9 @@ extern(C):
|
|||
|
||||
struct SpaceInvaders
|
||||
{
|
||||
__gshared const (char)* tips = "Use \"WASD\" keys to move and \"Space\" for shooting.";
|
||||
__gshared const (char)* tips = "Use \"WASD\" keys to move and \"Space\" for shooting.
|
||||
On start there is not to much to do. But you can spawn thousands of entities. You can even change guild for enemies to make them kilking themselves.
|
||||
You can add any component to any entity which sometimes can give fun results. This demo wasn't created with such combination in mind, but that is something which comes naturally with ECS.";
|
||||
|
||||
EntityTemplate* enemy_tmpl;
|
||||
EntityTemplate* ship_tmpl;
|
||||
|
|
@ -1019,7 +1021,7 @@ struct ShootingSystem
|
|||
foreach(i;0..data.length)
|
||||
{
|
||||
CWeapon* laser = &data.laser[i];
|
||||
laser.shoot_time += launcher.delta_time;
|
||||
laser.shoot_time += launcher.deltaTime;
|
||||
while(laser.shoot_time > CWeapon.levels[laser.level - 1].reload_time)
|
||||
{
|
||||
CVelocity laser_velocity;
|
||||
|
|
@ -1824,7 +1826,7 @@ struct AnimationSystem
|
|||
|
||||
void onUpdate(EntitiesData data)
|
||||
{
|
||||
float dt = launcher.delta_time * 0.01;
|
||||
float dt = launcher.deltaTime * 0.01;
|
||||
if(data.looped)
|
||||
{
|
||||
foreach(i;0..data.length)
|
||||
|
|
@ -1865,7 +1867,7 @@ struct ParticleSystem
|
|||
{
|
||||
foreach(i;0..data.length)
|
||||
{
|
||||
data.particle[i].life -= launcher.delta_time;
|
||||
data.particle[i].life -= launcher.deltaTime;
|
||||
if(data.particle[i].life < 0)launcher.manager.removeEntity(data.entitiy[i].id);
|
||||
}
|
||||
}
|
||||
|
|
@ -2086,6 +2088,7 @@ void spaceInvadersRegister()
|
|||
launcher.manager.registerComponent!CTargetPlayerShip;
|
||||
launcher.manager.registerComponent!CChildren;
|
||||
launcher.manager.registerComponent!CWeaponLocation;
|
||||
launcher.manager.registerComponent!CVelocityFactor;
|
||||
launcher.manager.registerComponent!CInit;
|
||||
launcher.manager.registerComponent!CBoss;
|
||||
launcher.manager.registerComponent!CParts;
|
||||
|
|
|
|||
|
|
@ -97,6 +97,10 @@ struct CVelocityFactor
|
|||
vec2 value = vec2(1);
|
||||
}
|
||||
|
||||
struct CStatic
|
||||
{
|
||||
mixin ECS.Component;
|
||||
}
|
||||
|
||||
struct DampingSystem
|
||||
{
|
||||
|
|
|
|||
|
|
@ -49,11 +49,6 @@ struct CBVH
|
|||
uint index;
|
||||
}
|
||||
|
||||
struct CStatic
|
||||
{
|
||||
mixin ECS.Component;
|
||||
}
|
||||
|
||||
struct CAABB
|
||||
{
|
||||
mixin ECS.Component;
|
||||
|
|
@ -1003,6 +998,7 @@ struct AABBUpdater
|
|||
@readonly CLocation[] location;
|
||||
@readonly CScale[] scale;
|
||||
@optional @readonly CRotation[] rotation;
|
||||
@optional @readonly CStatic[] static_flag;
|
||||
}
|
||||
|
||||
void onAddEntity(EntitiesData data)
|
||||
|
|
@ -1015,6 +1011,8 @@ struct AABBUpdater
|
|||
|
||||
void onUpdate(EntitiesData data)
|
||||
{
|
||||
if(data.static_flag)return;
|
||||
|
||||
foreach(i; 0..data.length)
|
||||
{
|
||||
data.bounding[i] = AABB(data.location[i]-data.scale[i],data.location[i]+data.scale[i]);
|
||||
|
|
|
|||
|
|
@ -395,7 +395,7 @@ struct GUIManager
|
|||
}
|
||||
}
|
||||
|
||||
void entityComponentsGUI()
|
||||
void templateComponentsGUI()
|
||||
{
|
||||
if(selected_template >= templates.length)return;
|
||||
EntityTemplate* tmpl = templates[selected_template].tmpl;
|
||||
|
|
@ -408,6 +408,19 @@ struct GUIManager
|
|||
}
|
||||
}
|
||||
|
||||
void entityComponentsGUI(Entity* entity)
|
||||
{
|
||||
if(!entity)return;
|
||||
EntityMeta meta = entity.getMeta();
|
||||
EntityManager.EntityInfo* info = meta.block.type_info;
|
||||
foreach(comp_id; info.components)
|
||||
{
|
||||
// void* data_ptr = tmpl.entity_data.ptr;
|
||||
void* comp_ptr = meta.getComponent(comp_id);//data_ptr + info.tmpl_deltas[comp_id];
|
||||
componentGUI(comp_id, comp_ptr);
|
||||
}
|
||||
}
|
||||
|
||||
void toolGui()
|
||||
{
|
||||
ImGuiStyle * style = igGetStyle();
|
||||
|
|
@ -436,7 +449,7 @@ struct GUIManager
|
|||
if(igIsItemHovered(0))igSetTooltip("Select entity to spawn (SHIFT + Scroll)");
|
||||
}
|
||||
style.Colors[ImGuiCol_Header] = col;
|
||||
entityComponentsGUI();
|
||||
templateComponentsGUI();
|
||||
break;
|
||||
case Tool.component_manipulator:
|
||||
if(components.length)
|
||||
|
|
@ -458,6 +471,11 @@ struct GUIManager
|
|||
if(selected_component < components.length)componentGUI(components[selected_component].component_id, components[selected_component].data);
|
||||
break;
|
||||
case Tool.selector:
|
||||
{
|
||||
Entity* entity = gEM.getEntity(launcher.selected_entity);
|
||||
style.Colors[ImGuiCol_Header] = col;
|
||||
entityComponentsGUI(entity);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue