Bikeshed: Implementing a command queue.

maik klein via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Mar 12 07:10:16 PST 2016


I wanted to implement a simple command queue in D. To give a bit 
of context, I want to create a command queue for opengl. Instead 
of interacting directly with opengl, you will create commands, 
put them in a queue and then the renderer will read those 
commands and execute the correct OpenGl calls.


I have a few options:

I could use an ADT to create commands but then all commands would 
have the size of the biggest command, also Algebraic is not nice 
nicest thing in D.

I could use runtime polymorphism `class SomeCommand: Command{}` 
but then I would end up with a lot of pointers in the queue, also 
I would need to worry about the allocations.

I have also seen this, but it is a bit more low level and is 
similar to assembly.

Queue:
Command1
int
int
Command2
float
Command3
Command4
int
float double

The first entry would always be the command which is followed by 
the arguments. So you would pop the command out and with the 
command you know how far you need to go into the queue

//pseudo code
auto c = queue.pop!Command;

if(c == Command1){
    int arg1 = queue.pop!int;
    int arg2 = queue.pop!int;
}
if(c == Command2){
    int arg1 = queue.pop!float;

}

How would you implement a simple command queue?







More information about the Digitalmars-d-learn mailing list