-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:
Mergul 2021-03-01 12:16:02 +01:00
parent 1acd0df0ef
commit 56f870bac6
21 changed files with 332 additions and 133 deletions

View file

@ -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;