-Events system update order is now choosen according to system priority
-added mixin for adding exluded components using it's type -demos: *added GUI for selecting templates and choosing tools *change SpaceInvades SideMove system to not using events for better performance and multithreading *added Entites spawning support *fixed some Snake demo bugs *GUI work's better now
This commit is contained in:
parent
19fc440ed6
commit
1f78f2506c
9 changed files with 436 additions and 60 deletions
|
|
@ -33,6 +33,12 @@ enum Tool
|
|||
|
||||
__gshared const (char)*[3] tool_strings = ["Entity spawner", "Component manipulator", "Selector"];
|
||||
|
||||
struct Mouse
|
||||
{
|
||||
vec2 position;
|
||||
bool left, right, middle;
|
||||
}
|
||||
|
||||
struct Launcher
|
||||
{
|
||||
ECSJobUpdater* job_updater;
|
||||
|
|
@ -44,6 +50,7 @@ struct Launcher
|
|||
bool function() loop;
|
||||
void function() end;
|
||||
void function(SDL_Event*) event;
|
||||
void function(vec2, Tool, int) tool;
|
||||
ivec2 window_size = ivec2(1024,768);
|
||||
Renderer renderer;
|
||||
ubyte[] keys;
|
||||
|
|
@ -55,6 +62,9 @@ struct Launcher
|
|||
uint fps;
|
||||
|
||||
Tool used_tool;
|
||||
int tool_size = 0;
|
||||
float tool_repeat = 0;
|
||||
float repeat_time = 0;
|
||||
|
||||
bool swap_interval = true;
|
||||
|
||||
|
|
@ -71,6 +81,8 @@ struct Launcher
|
|||
int plot_index;
|
||||
PlotStruct[] plot_values;
|
||||
|
||||
Mouse mouse;
|
||||
|
||||
struct PlotStruct
|
||||
{
|
||||
float delta_time = 0;
|
||||
|
|
@ -78,7 +90,7 @@ struct Launcher
|
|||
float draw_time = 0;
|
||||
}
|
||||
|
||||
void switchDemo(void function() start, bool function() loop, void function() end, void function(SDL_Event*) event, const (char)* tips)
|
||||
void switchDemo(void function() start, bool function() loop, void function() end, void function(SDL_Event*) event, void function(vec2, Tool, int) tool, const (char)* tips)
|
||||
{
|
||||
gui_manager.clear();
|
||||
|
||||
|
|
@ -93,6 +105,7 @@ struct Launcher
|
|||
this.end = end;
|
||||
this.event = event;
|
||||
this.tips = tips;
|
||||
this.tool = tool;
|
||||
}
|
||||
|
||||
bool getKeyState(SDL_Scancode key)
|
||||
|
|
@ -204,6 +217,46 @@ void mainLoop(void* arg)
|
|||
default:break;
|
||||
}
|
||||
}
|
||||
else if(event.type == SDL_MOUSEBUTTONDOWN)
|
||||
{
|
||||
switch(event.button.button)
|
||||
{
|
||||
case SDL_BUTTON_LEFT:launcher.mouse.left = true;break;
|
||||
case SDL_BUTTON_RIGHT:launcher.mouse.right = true;break;
|
||||
case SDL_BUTTON_MIDDLE:launcher.mouse.middle = true;break;
|
||||
default:break;
|
||||
}
|
||||
if(launcher.tool && event.button.button == SDL_BUTTON_LEFT && launcher.tool_repeat == 0 && !igIsWindowHovered(ImGuiHoveredFlags_AnyWindow))
|
||||
{
|
||||
launcher.tool(vec2(event.button.x, launcher.window_size.y - event.button.y), launcher.used_tool, launcher.tool_size);
|
||||
}
|
||||
}
|
||||
else if(event.type == SDL_MOUSEBUTTONUP)
|
||||
{
|
||||
switch(event.button.button)
|
||||
{
|
||||
case SDL_BUTTON_LEFT:launcher.mouse.left = false;break;
|
||||
case SDL_BUTTON_RIGHT:launcher.mouse.right = false;break;
|
||||
case SDL_BUTTON_MIDDLE:launcher.mouse.middle = false;break;
|
||||
default:break;
|
||||
}
|
||||
}
|
||||
else if(event.type == SDL_MOUSEMOTION)
|
||||
{
|
||||
launcher.mouse.position = vec2(event.motion.x, launcher.window_size.y - event.motion.y);
|
||||
}
|
||||
}
|
||||
|
||||
if(launcher.tool && launcher.tool_repeat != 0 && launcher.mouse.left && !igIsWindowHovered(ImGuiHoveredFlags_AnyWindow) && !igIsWindowFocused(ImGuiFocusedFlags_AnyWindow))
|
||||
{
|
||||
float range = 500.0 / cast(float)launcher.tool_repeat;
|
||||
launcher.repeat_time += launcher.delta_time;
|
||||
while(launcher.repeat_time > range)
|
||||
{
|
||||
launcher.repeat_time -= range;
|
||||
launcher.tool(launcher.mouse.position, launcher.used_tool, launcher.tool_size);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
version(WebAssembly)
|
||||
|
|
@ -236,17 +289,17 @@ void mainLoop(void* arg)
|
|||
if(igMenuItemBool("Simpe",null,false,true))
|
||||
{
|
||||
import demos.simple;
|
||||
launcher.switchDemo(&simpleStart,&simpleLoop,&simpleEnd,&simpleEvent,Simple.tips);
|
||||
launcher.switchDemo(&simpleStart,&simpleLoop,&simpleEnd,&simpleEvent,&simpleTool,Simple.tips);
|
||||
}
|
||||
if(igMenuItemBool("Snake",null,false,true))
|
||||
{
|
||||
import demos.snake;
|
||||
launcher.switchDemo(&snakeStart,&snakeLoop,&snakeEnd,&snakeEvent,Snake.tips);
|
||||
launcher.switchDemo(&snakeStart,&snakeLoop,&snakeEnd,&snakeEvent,&snakeTool,Snake.tips);
|
||||
}
|
||||
if(igMenuItemBool("Space invaders",null,false,true))
|
||||
{
|
||||
import demos.space_invaders;
|
||||
launcher.switchDemo(&spaceInvadersStart,&spaceInvadersLoop,&spaceInvadersEnd,&spaceInvadersEvent,SpaceInvaders.tips);
|
||||
launcher.switchDemo(&spaceInvadersStart,&spaceInvadersLoop,&spaceInvadersEnd,&spaceInvadersEvent,&spaceInvadersTool,SpaceInvaders.tips);
|
||||
}
|
||||
igEndMenu();
|
||||
}
|
||||
|
|
@ -386,23 +439,44 @@ void mainLoop(void* arg)
|
|||
igSetNextWindowSize(ImVec2(250, 250), ImGuiCond_Once);
|
||||
if(igBegin("Demo",&launcher.show_demo_wnd,0))
|
||||
{
|
||||
ImDrawList* draw_list = igGetWindowDrawList();
|
||||
//igBeginGroup();
|
||||
launcher.gui_manager.gui();
|
||||
if(igBeginCombo("Tool",tool_strings[launcher.used_tool],0))
|
||||
//igEndGroup();
|
||||
//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);
|
||||
if(igCollapsingHeader("Tool##ToolHeader", ImGuiTreeNodeFlags_SpanAvailWidth))
|
||||
{
|
||||
if(igSelectable("Entity spawner",false,0,ImVec2(0,0)))
|
||||
igIndent(8);
|
||||
igBeginGroup();
|
||||
if(igBeginCombo("Tool",tool_strings[launcher.used_tool],0))
|
||||
{
|
||||
launcher.used_tool = Tool.entity_spawner;
|
||||
if(igSelectable("Entity spawner",false,0,ImVec2(0,0)))
|
||||
{
|
||||
launcher.used_tool = Tool.entity_spawner;
|
||||
}
|
||||
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;
|
||||
}
|
||||
igEndCombo();
|
||||
}
|
||||
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;
|
||||
}
|
||||
igEndCombo();
|
||||
|
||||
igSliderInt("Tool size", &launcher.tool_size, 0, 256, null);
|
||||
igSliderFloat("Tool repeat", &launcher.tool_repeat, 0, 1024, null, 4);
|
||||
launcher.gui_manager.toolGui();
|
||||
igEndGroup();
|
||||
ImDrawList_AddRect(draw_list, igGetItemRectMin(), igGetItemRectMax(), igColorConvertFloat4ToU32(ImVec4(0.4,0.4,0.4,0.4)), 4, ImDrawCornerFlags_All, 1);
|
||||
igUnindent(8);
|
||||
}
|
||||
|
||||
//igEndChild();
|
||||
//igEndChildFrame();
|
||||
if(igButton("Clear",ImVec2(-1,0)))
|
||||
{
|
||||
launcher.manager.begin();
|
||||
|
|
@ -629,7 +703,7 @@ int main(int argc, char** argv)
|
|||
|
||||
{
|
||||
import demos.simple;
|
||||
launcher.switchDemo(&simpleStart,&simpleLoop,&simpleEnd,&simpleEvent,Simple.tips);
|
||||
launcher.switchDemo(&simpleStart,&simpleLoop,&simpleEnd,&simpleEvent,&simpleTool,Simple.tips);
|
||||
}
|
||||
|
||||
int key_num;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue