Demos update

-added some new types to gui manager + some fixes
-TexCoordsManager now working (probably)
-added CRenderDefault components which makes entities without texcoords possible to draw
-makes better way of binding demos to launcher
-moved some registration related to rendering to one function (basic components + draw system)
-added Sandbox demo (demo which takes all demos to one demo)
-extends ParticlesDemo play area
-added BirckBreaker demo (WIP)
-added special material to additive particles
-added whole bunch of rendering code to rendering module
-added ability to show filtered entities (blinking)
This commit is contained in:
Mergul 2020-07-01 19:45:53 +02:00
parent ef4faf2755
commit b0b64b965f
12 changed files with 1122 additions and 74 deletions

View file

@ -41,6 +41,15 @@ struct Mouse
bool left, right, middle;
}
struct DemoCallbacks
{
void function() initialize;
void function() deinitialize;
bool function() loop;
void function(SDL_Event*) event;
const (char)* tips;
}
struct Launcher
{
ECSJobUpdater* job_updater;
@ -49,9 +58,9 @@ struct Launcher
SDL_Window* window;
SDL_GLContext gl_context;
EntityManager* manager;
bool function() loop;
/*bool function() loop;
void function() end;
void function(SDL_Event*) event;
void function(SDL_Event*) event;*/
//void function(vec2, Tool, int, bool) tool;
float scalling;
ivec2 window_size = ivec2(1024,768);
@ -74,12 +83,13 @@ struct Launcher
bool override_ = true;
bool tool_mode = true;
ToolCircle* tool_circle;
bool show_filtered;
bool swap_interval = true;
float windows_alpha = 0.75;
const (char)* tips;
//const (char)* tips;
bool show_stat_wnd = true;
bool show_tips = true;
@ -99,12 +109,14 @@ 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)
DemoCallbacks demo;
void switchDemo(DemoCallbacks callbacks)//void function() start, bool function() loop, void function() end, void function(SDL_Event*) event, const (char)* tips)
{
gui_manager.clear();
//launcher.ent
if(this.end)this.end();
if(this.demo.deinitialize)this.demo.deinitialize();
manager.begin();
manager.update("clean");
@ -118,14 +130,29 @@ struct Launcher
/*launcher.manager.getSystem(CountSystem.system_id).enable();
launcher.manager.getSystem(CleanSystem.system_id).enable();//*/
if(start)start();
this.loop = loop;
if(callbacks.initialize)callbacks.initialize();
demo = callbacks;
/*this.loop = loop;
this.end = end;
this.event = event;
this.tips = tips;
this.tips = tips;*/
//this.tool = tool;
}
bool filterEntity(ref const Entity entity)
{
EntityMeta meta = entity.getMeta();
foreach(id;gui_manager.filter_list)
{
if(!meta.hasComponent(id))return false;
}
if(used_tool == Tool.component_manipulator)
{
if(!meta.hasComponent(gui_manager.getSelectedComponent().component_id))return false;
}
return true;
}
void processTool(vec2 position, bool mode)
{
static struct Iterator
@ -361,7 +388,7 @@ void mainLoop(void* arg)
while (SDL_PollEvent(&event))
{
ImGui_ImplSDL2_ProcessEvent(&event);
if(launcher.event)launcher.event(&event);
if(launcher.demo.event)launcher.demo.event(&event);
if (event.type == SDL_QUIT || (event.type == SDL_KEYDOWN && event.key.keysym.scancode == SDL_SCANCODE_ESCAPE)) {
quit();
*cast(bool*)arg = false;
@ -534,22 +561,32 @@ void mainLoop(void* arg)
if(igMenuItemBool("Simpe",null,false,true))
{
import demos.simple;
launcher.switchDemo(&simpleStart,&simpleLoop,&simpleEnd,&simpleEvent,Simple.tips);
launcher.switchDemo(getSimpleDemo());//&simpleStart,&simpleLoop,&simpleEnd,&simpleEvent,Simple.tips);
}
if(igMenuItemBool("Snake",null,false,true))
{
import demos.snake;
launcher.switchDemo(&snakeStart,&snakeLoop,&snakeEnd,&snakeEvent,Snake.tips);
launcher.switchDemo(getSnakeDemo());//&snakeStart,&snakeLoop,&snakeEnd,&snakeEvent,Snake.tips);
}
if(igMenuItemBool("Space invaders",null,false,true))
if(igMenuItemBool("Space Invaders",null,false,true))
{
import demos.space_invaders;
launcher.switchDemo(&spaceInvadersStart,&spaceInvadersLoop,&spaceInvadersEnd,&spaceInvadersEvent,SpaceInvaders.tips);
launcher.switchDemo(getSpaceInvadersDemo());//&spaceInvadersStart,&spaceInvadersLoop,&spaceInvadersEnd,&spaceInvadersEvent,SpaceInvaders.tips);
}
if(igMenuItemBool("Particles",null,false,true))
{
import demos.particles;
launcher.switchDemo(&particlesStart,&particlesLoop,&particlesEnd,&particlesEvent,ParticlesDemo.tips);
launcher.switchDemo(getParticlesDemo());//&particlesStart,&particlesLoop,&particlesEnd,&particlesEvent,ParticlesDemo.tips);
}
if(igMenuItemBool("Brick Breaker",null,false,true))
{
import demos.brick_breaker;
launcher.switchDemo(getBrickBreakerDemo());//&particlesStart,&particlesLoop,&particlesEnd,&particlesEvent,ParticlesDemo.tips);
}
if(igMenuItemBool("Sandbox",null,false,true))
{
import demos.sandbox;
launcher.switchDemo(getSanboxDemo());//&particlesStart,&particlesLoop,&particlesEnd,&particlesEvent,ParticlesDemo.tips);
}
igEndMenu();
}
@ -683,7 +720,7 @@ void mainLoop(void* arg)
igSetNextWindowBgAlpha(launcher.windows_alpha);
if(igBegin("Tips",&launcher.show_tips,ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoSavedSettings))
{
igTextWrapped(launcher.tips);
igTextWrapped(launcher.demo.tips);
}
igEnd();
}
@ -726,9 +763,11 @@ void mainLoop(void* arg)
if(igIsItemHovered(0))igSetTooltip("Select tool (CTRL + 1,2,3)");
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)
{
igSameLine(0,4);
igCheckbox("Override", &launcher.override_);
}
@ -823,7 +862,7 @@ void mainLoop(void* arg)
double loop_time = launcher.getTime();
launcher.job_updater.pool.tryWaitCount = 10000;
if(launcher.loop && !launcher.loop())
if(launcher.demo.loop && !launcher.demo.loop())
{
quit();
*cast(bool*)arg = false;
@ -1053,6 +1092,8 @@ int app_main(int argc, char** argv)
loadGFX();
launcher.renderer.initialize();
import game_core.rendering : TexCoordsManager;
TexCoordsManager.initialize();
import mmutils.thread_pool : ThreadPool;
launcher.threads = ThreadPool.getCPUCoresCount();
@ -1065,8 +1106,10 @@ int app_main(int argc, char** argv)
import demos.space_invaders;
import demos.particles;
// launcher.switchDemo(&spaceInvadersStart,&spaceInvadersLoop,&spaceInvadersEnd,&spaceInvadersEvent,SpaceInvaders.tips);
launcher.switchDemo(&particlesStart,&particlesLoop,&particlesEnd,&particlesEvent,ParticlesDemo.tips);
// launcher.switchDemo(&particlesStart,&particlesLoop,&particlesEnd,&particlesEvent,ParticlesDemo.tips);
// launcher.switchDemo(&simpleStart,&simpleLoop,&simpleEnd,&simpleEvent,Simple.tips);
// launcher.switchDemo(getParticlesDemo());
launcher.switchDemo(getSimpleDemo());
}
int key_num;
@ -1094,6 +1137,7 @@ int app_main(int argc, char** argv)
}
}
TexCoordsManager.destroy();
EntityManager.destroy();
return 0;
@ -1198,13 +1242,22 @@ void loadGFX()
Shader vsh3;
vsh3.create();
vsh3.load("assets/shaders/additive_particles.vp");
vsh3.compile();
Shader fsh3;
fsh3.create();
fsh3.load("assets/shaders/additive_particles.fp");
fsh3.compile();
GfxConfig.materials[2].create();
GfxConfig.materials[2].data.blend_mode = Material.BlendMode.opaque;
GfxConfig.materials[2].data.mode = Material.TransformMode.position;
//Material.ShaderModule[1] modules = [Material.ShaderModule(vsh,fsh)];
GfxConfig.materials[2].attachModules(modules);
Material.ShaderModule[1] modules3 = [Material.ShaderModule(vsh3,fsh3)];
GfxConfig.materials[2].attachModules(modules3);
//GfxConfig.materials[0].
//GfxConfig.materials[0].load(load_data.materials[i].str);
GfxConfig.materials[2].compile();