Improved Demo and multithreading rendering:
-added support for multithreaded rendering (fast) -improved shaders -added support for rendering depth -added rendering color support -improved DeptThreadPool (dynamics setting number of tryWait counts before TryWait. Low cpu usage with high responivity) -added possibility to change number of threads
This commit is contained in:
parent
f6e7af1014
commit
c94510a487
8 changed files with 311 additions and 105 deletions
|
|
@ -58,6 +58,7 @@ struct Launcher
|
|||
uint style = 3;
|
||||
uint entities_count;
|
||||
bool multithreading;
|
||||
int threads;
|
||||
ulong timer_freq;
|
||||
double delta_time;
|
||||
uint fps;
|
||||
|
|
@ -253,13 +254,12 @@ void mainLoop(void* arg)
|
|||
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*100;
|
||||
launcher.repeat_time += launcher.delta_time;
|
||||
while(launcher.repeat_time > range)
|
||||
{
|
||||
launcher.repeat_time -= range;
|
||||
launcher.tool((launcher.mouse.position*launcher.scalling)-launcher.render_position, launcher.used_tool, launcher.tool_size);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
version(WebAssembly)
|
||||
|
|
@ -317,6 +317,14 @@ void mainLoop(void* arg)
|
|||
{
|
||||
launcher.multithreading = !launcher.multithreading;
|
||||
}
|
||||
igSetNextItemWidth(0);
|
||||
igLabelText("Threads:",null);
|
||||
igSameLine(0,4);
|
||||
if(igSliderInt("##Threads",&launcher.threads, 1, 12, null))//"Multithreading", null, launcher.multithreading, true))
|
||||
{
|
||||
launcher.job_updater.pool.setThreadsNum(launcher.threads);
|
||||
//launcher.threads = !launcher.multithreading;
|
||||
}
|
||||
if(igBeginMenu("Show",true))
|
||||
{
|
||||
if(igMenuItemBool("Statistics",null,launcher.show_stat_wnd,true))
|
||||
|
|
@ -539,11 +547,14 @@ void mainLoop(void* arg)
|
|||
launcher.renderer.clear();
|
||||
|
||||
double loop_time = launcher.getTime();
|
||||
launcher.job_updater.pool.tryWaitCount = 5000;
|
||||
if(launcher.loop && !launcher.loop())
|
||||
{
|
||||
quit();
|
||||
*cast(bool*)arg = false;
|
||||
}
|
||||
launcher.job_updater.pool.tryWaitCount = 10;
|
||||
|
||||
loop_time = launcher.getTime() - loop_time;
|
||||
|
||||
double draw_time = launcher.getTime();
|
||||
|
|
@ -785,7 +796,15 @@ void loadGFX()
|
|||
GfxConfig.materials[0].compile();
|
||||
GfxConfig.materials[0].bindAttribLocation("positions",0);
|
||||
GfxConfig.materials[0].bindAttribLocation("tex_coords",1);
|
||||
GfxConfig.materials[0].bindAttribLocation("depth",2);
|
||||
GfxConfig.materials[0].bindAttribLocation("vcolor",3);
|
||||
GfxConfig.materials[0].link();
|
||||
|
||||
/* import std.stdio;
|
||||
writeln("positions ",glGetAttribLocation(GfxConfig.materials[0].data.modules[0].gl_handle,"positions"));
|
||||
writeln("tex_coords ",glGetAttribLocation(GfxConfig.materials[0].data.modules[0].gl_handle,"tex_coords"));
|
||||
writeln("depth ",glGetAttribLocation(GfxConfig.materials[0].data.modules[0].gl_handle,"depth"));
|
||||
writeln("vcolor ",glGetAttribLocation(GfxConfig.materials[0].data.modules[0].gl_handle,"vcolor"));*/
|
||||
|
||||
GfxConfig.materials[0].data.uniforms = Mallocator.makeArray!(Material.Uniform)(3);
|
||||
GfxConfig.materials[0].data.uniforms[0] = Material.Uniform(Material.Type.float4, GfxConfig.materials[0].getLocation("matrix_1"), 0);
|
||||
|
|
|
|||
|
|
@ -47,23 +47,25 @@ struct CTexture
|
|||
|
||||
struct DrawSystem
|
||||
{
|
||||
mixin ECS.System!1;
|
||||
mixin ECS.System!32;
|
||||
|
||||
struct EntitiesData
|
||||
{
|
||||
uint length;
|
||||
uint thread_id;
|
||||
@readonly CTexture[] textures;
|
||||
@readonly CLocation[] locations;
|
||||
}
|
||||
|
||||
void onUpdate(EntitiesData data)
|
||||
{
|
||||
if(launcher.renderer.item_id >= launcher.renderer.MaxObjects)return;//simple leave loop if max visible objects count was reached
|
||||
if(launcher.renderer.prepared_items >= launcher.renderer.MaxObjects)return;//simple leave loop if max visible objects count was reached
|
||||
foreach(i; 0..data.length)
|
||||
{
|
||||
launcher.renderer.draw(data.textures[i].tex, data.locations[i].location, vec2(16,16), vec4(0,0,1,1), 0, 0 , 0);
|
||||
launcher.renderer.draw(data.textures[i].tex, data.locations[i].location, vec2(16,16), vec4(0,0,1,1), cast(ushort)(data.locations[i].y*64+data.locations[i].x), uint.max, 0, 0, 0, data.thread_id);
|
||||
//draw(renderer, data.textures[i].tex, data.locations[i], vec2(32,32), vec4(0,0,1,1));
|
||||
}
|
||||
if(data.thread_id == 0)launcher.renderer.pushData();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -607,7 +607,7 @@ struct DrawAppleSystem
|
|||
{
|
||||
foreach(i; 0..data.location.length)
|
||||
{
|
||||
launcher.renderer.draw(snake.texture, vec2(data.location[i].x*16,data.location[i].y*16), vec2(16,16), vec4(0,32*px,16*px,16*px), 0, 0 , 0);
|
||||
launcher.renderer.draw(snake.texture, vec2(data.location[i].x*16,data.location[i].y*16), vec2(16,16), vec4(0,32*px,16*px,16*px), 0, uint.max, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -677,16 +677,16 @@ struct DrawSnakeSystem
|
|||
{
|
||||
final switch(cast(ubyte)part)
|
||||
{
|
||||
case SnakePart.tail_up:launcher.renderer.draw(.snake.texture, cast(vec2)loc, vec2(16,16), vec4(16,112,16,16)*px, 0, 0, 0);break;
|
||||
case SnakePart.tail_down:launcher.renderer.draw(.snake.texture, cast(vec2)loc, vec2(16,16), vec4(0,112,16,16)*px, 0, 0, 0);break;
|
||||
case SnakePart.tail_left:launcher.renderer.draw(.snake.texture, cast(vec2)loc, vec2(16,16), vec4(32,112,16,16)*px, 0, 0, 0);break;
|
||||
case SnakePart.tail_right:launcher.renderer.draw(.snake.texture, cast(vec2)loc, vec2(16,16), vec4(0,144,16,16)*px, 0, 0, 0);break;
|
||||
case SnakePart.turn_ld:launcher.renderer.draw(.snake.texture, cast(vec2)loc, vec2(16,16), vec4(64,128,16,16)*px, 0, 0, 0);break;
|
||||
case SnakePart.turn_lu:launcher.renderer.draw(.snake.texture, cast(vec2)loc, vec2(16,16), vec4(32,144,16,16)*px, 0, 0, 0);break;
|
||||
case SnakePart.turn_rd:launcher.renderer.draw(.snake.texture, cast(vec2)loc, vec2(16,16), vec4(16,144,16,16)*px, 0, 0, 0);break;
|
||||
case SnakePart.turn_ru:launcher.renderer.draw(.snake.texture, cast(vec2)loc, vec2(16,16), vec4(64,112,16,16)*px, 0, 0, 0);break;
|
||||
case SnakePart.vertical:launcher.renderer.draw(.snake.texture, cast(vec2)loc, vec2(16,16), vec4(16,128,16,16)*px, 0, 0, 0);break;
|
||||
case SnakePart.horizontal:launcher.renderer.draw(.snake.texture, cast(vec2)loc, vec2(16,16), vec4(48,128,16,16)*px, 0, 0, 0);break;
|
||||
case SnakePart.tail_up:launcher.renderer.draw(.snake.texture, cast(vec2)loc, vec2(16,16), vec4(16,112,16,16)*px, 0, uint.max, 0);break;
|
||||
case SnakePart.tail_down:launcher.renderer.draw(.snake.texture, cast(vec2)loc, vec2(16,16), vec4(0,112,16,16)*px, 0, uint.max, 0);break;
|
||||
case SnakePart.tail_left:launcher.renderer.draw(.snake.texture, cast(vec2)loc, vec2(16,16), vec4(32,112,16,16)*px, 0, uint.max, 0);break;
|
||||
case SnakePart.tail_right:launcher.renderer.draw(.snake.texture, cast(vec2)loc, vec2(16,16), vec4(0,144,16,16)*px, 0, uint.max, 0);break;
|
||||
case SnakePart.turn_ld:launcher.renderer.draw(.snake.texture, cast(vec2)loc, vec2(16,16), vec4(64,128,16,16)*px, 0, uint.max, 0);break;
|
||||
case SnakePart.turn_lu:launcher.renderer.draw(.snake.texture, cast(vec2)loc, vec2(16,16), vec4(32,144,16,16)*px, 0, uint.max, 0);break;
|
||||
case SnakePart.turn_rd:launcher.renderer.draw(.snake.texture, cast(vec2)loc, vec2(16,16), vec4(16,144,16,16)*px, 0, uint.max, 0);break;
|
||||
case SnakePart.turn_ru:launcher.renderer.draw(.snake.texture, cast(vec2)loc, vec2(16,16), vec4(64,112,16,16)*px, 0, uint.max, 0);break;
|
||||
case SnakePart.vertical:launcher.renderer.draw(.snake.texture, cast(vec2)loc, vec2(16,16), vec4(16,128,16,16)*px, 0, uint.max, 0);break;
|
||||
case SnakePart.horizontal:launcher.renderer.draw(.snake.texture, cast(vec2)loc, vec2(16,16), vec4(48,128,16,16)*px, 0, uint.max, 0);break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -698,10 +698,10 @@ struct DrawSnakeSystem
|
|||
scope vec2 loc = cast(vec2)(data.location[i].location * 16);
|
||||
final switch(snake.direction)
|
||||
{
|
||||
case CMovement.Direction.up:launcher.renderer.draw(.snake.texture, vec2(data.location[i].x*16,data.location[i].y*16), vec2(16,16), vec4(48,112,16,16)*px, 0, 0 , 0);break;
|
||||
case CMovement.Direction.down:launcher.renderer.draw(.snake.texture, vec2(data.location[i].x*16,data.location[i].y*16), vec2(16,16), vec4(48,144,16,16)*px, 0, 0 , 0);break;
|
||||
case CMovement.Direction.left:launcher.renderer.draw(.snake.texture, vec2(data.location[i].x*16,data.location[i].y*16), vec2(16,16), vec4(0,128,16,16)*px, 0, 0 , 0);break;
|
||||
case CMovement.Direction.right:launcher.renderer.draw(.snake.texture, vec2(data.location[i].x*16,data.location[i].y*16), vec2(16,16), vec4(32,128,16,16)*px, 0, 0 , 0);break;
|
||||
case CMovement.Direction.up:launcher.renderer.draw(.snake.texture, vec2(data.location[i].x*16,data.location[i].y*16), vec2(16,16), vec4(48,112,16,16)*px, 0, uint.max, 0);break;
|
||||
case CMovement.Direction.down:launcher.renderer.draw(.snake.texture, vec2(data.location[i].x*16,data.location[i].y*16), vec2(16,16), vec4(48,144,16,16)*px, 0, uint.max, 0);break;
|
||||
case CMovement.Direction.left:launcher.renderer.draw(.snake.texture, vec2(data.location[i].x*16,data.location[i].y*16), vec2(16,16), vec4(0,128,16,16)*px, 0, uint.max, 0);break;
|
||||
case CMovement.Direction.right:launcher.renderer.draw(.snake.texture, vec2(data.location[i].x*16,data.location[i].y*16), vec2(16,16), vec4(32,128,16,16)*px, 0, uint.max, 0);break;
|
||||
}
|
||||
if(snake.parts.length >1)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -183,6 +183,8 @@ struct CDepth
|
|||
{
|
||||
mixin ECS.Component;
|
||||
|
||||
alias depth this;
|
||||
|
||||
short depth;
|
||||
}
|
||||
|
||||
|
|
@ -208,23 +210,33 @@ struct EChangeDirection
|
|||
|
||||
struct DrawSystem
|
||||
{
|
||||
mixin ECS.System!1;
|
||||
mixin ECS.System!32;
|
||||
|
||||
struct EntitiesData
|
||||
{
|
||||
uint length;
|
||||
uint thread_id;
|
||||
@readonly CTexture[] textures;
|
||||
@readonly CLocation[] locations;
|
||||
@readonly CScale[] scale;
|
||||
@readonly @optional CDepth[] depth;
|
||||
}
|
||||
|
||||
void onUpdate(EntitiesData data)
|
||||
{
|
||||
foreach(i; 0..data.length)
|
||||
{
|
||||
launcher.renderer.draw(data.textures[i].tex, data.locations[i].value, data.scale[i], data.textures[i].coords, 0, 0 , 0);
|
||||
//draw(renderer, data.textures[i].tex, data.locations[i], vec2(32,32), vec4(0,0,1,1));
|
||||
}
|
||||
if(!data.depth)
|
||||
foreach(i; 0..data.length)
|
||||
{
|
||||
launcher.renderer.draw(data.textures[i].tex, data.locations[i].value, data.scale[i], data.textures[i].coords, cast(short)data.locations[i].y, uint.max, 0, 0, 0, data.thread_id);
|
||||
//draw(renderer, data.textures[i].tex, data.locations[i], vec2(32,32), vec4(0,0,1,1));
|
||||
}
|
||||
else
|
||||
foreach(i; 0..data.length)
|
||||
{
|
||||
launcher.renderer.draw(data.textures[i].tex, data.locations[i].value, data.scale[i], data.textures[i].coords, cast(short)(data.depth[i] * 64 + data.locations[i].y), uint.max, 0, 0, 0, data.thread_id);
|
||||
//draw(renderer, data.textures[i].tex, data.locations[i], vec2(32,32), vec4(0,0,1,1));
|
||||
}
|
||||
if(data.thread_id == 0)launcher.renderer.pushData();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue