tag:blogger.com,1999:blog-4447090642049340023.post3148458909807170308..comments2023-10-30T01:24:28.459-07:00Comments on Angelus blog: Query commands executionAngelushttp://www.blogger.com/profile/02218727575338098906noreply@blogger.comBlogger15125tag:blogger.com,1999:blog-4447090642049340023.post-71258605127012516422013-09-26T06:52:58.963-07:002013-09-26T06:52:58.963-07:00Yes wrap is ring buffer: return to begin. And ther...Yes wrap is ring buffer: return to begin. And there is no option to override because I use m_MemoryWritePtr and m_MemoryReadPtr. So when I add new command there is check if there still enough space for this new command. If there is not return assertion. <br /><br />Of course there is possibility to wait on release of memory but on this point I decided that there should always be space for new command if not then one of bellow options:<br />- it's mean that something is wrong and you need to check it<br />- everything is ok you only need to increase size of memory size.Angelushttps://www.blogger.com/profile/02218727575338098906noreply@blogger.comtag:blogger.com,1999:blog-4447090642049340023.post-67563740575649179792013-09-26T06:38:15.015-07:002013-09-26T06:38:15.015-07:00ovverride accidetally of course!ovverride accidetally of course!Anonymoushttps://www.blogger.com/profile/17641927094685224341noreply@blogger.comtag:blogger.com,1999:blog-4447090642049340023.post-46837779827473908132013-09-26T06:37:44.282-07:002013-09-26T06:37:44.282-07:00Ok, now its all clear! :) Thanks for explaination!...Ok, now its all clear! :) Thanks for explaination!<br /><br />Yet another thing, when WRAP command is issued to the ring buffer? Is there possibility to everride unexecuted command?Anonymoushttps://www.blogger.com/profile/17641927094685224341noreply@blogger.comtag:blogger.com,1999:blog-4447090642049340023.post-80848744386156623382013-09-26T06:06:24.681-07:002013-09-26T06:06:24.681-07:00Ok so it look like that :
// execute command (re...Ok so it look like that : <br /><br />// execute command (return true if its WRAP)<br />if (execCommand(cmd, m_MemoryReadPtr))<br />{<br />// WRAP COMMAND - return to begin of memory on which commands work (functionality of ring buffer).<br />m_MemoryReadPtr = m_Memory;<br />}<br />else<br />{<br />// this was normal command and we used it [cmd_data] so we jump over it (getCmdSize(..) return size of SCommand<T>::SData )<br />m_MemoryReadPtr += getCmdSize(cmd);<br />}<br /><br />I see that I need to change some names so they would be easier to understand.Angelushttps://www.blogger.com/profile/02218727575338098906noreply@blogger.comtag:blogger.com,1999:blog-4447090642049340023.post-7887444465403684462013-09-26T05:57:19.255-07:002013-09-26T05:57:19.255-07:00One more thing:
// if command cmd is executed wit...One more thing:<br /><br />// if command cmd is executed with data under m_MemoryReadPtr<br />if (execCommand(cmd, m_MemoryReadPtr))<br /> {<br />// don't get it what m_Memory stands for? Can you explain?<br />// is it memory holding results of that command or what?<br /> // WRAP COMMAND<br /> m_MemoryReadPtr = m_Memory;<br /> }<br /> else<br /> {<br />// ok so if it faild you simply skip to next cmd_id<br /> m_MemoryReadPtr += getCmdSize(cmd);<br /> }Anonymoushttps://www.blogger.com/profile/17641927094685224341noreply@blogger.comtag:blogger.com,1999:blog-4447090642049340023.post-11815187762956927162013-09-26T05:44:01.901-07:002013-09-26T05:44:01.901-07:00Code isn't exactly the same as in engine :] th...Code isn't exactly the same as in engine :] there I have some comments/events/descriptions of classes and how they work. Here I removed them so code would be shorter.<br /><br />As you said: on create of command memory is fill with data. This solution is nice because it minimize memory usage and allow me for work on static pool of memory. Combined with ring buffer functionality it's really powerful tool :] <br />Angelushttps://www.blogger.com/profile/02218727575338098906noreply@blogger.comtag:blogger.com,1999:blog-4447090642049340023.post-53885551405355087172013-09-26T05:35:45.754-07:002013-09-26T05:35:45.754-07:00Now i get it :) Put some notes to that code or you...Now i get it :) Put some notes to that code or you will not remember a thing in years to come ;)<br /><br />So your memmory layout would be something like this:<br /><br />[cmd_id][cmd_data][cmd_id][cmd_data]<br /><br />and its raw. You rely on data size to point to propper memory point and read data of desired size based on cmd_id. So I assume when you create a command you are actually doing memcpy to push it to that memmory block. Right?Anonymoushttps://www.blogger.com/profile/17641927094685224341noreply@blogger.comtag:blogger.com,1999:blog-4447090642049340023.post-3109201909141281662013-09-26T04:44:01.202-07:002013-09-26T04:44:01.202-07:00No everything is fine I waited for work permit. Bu...No everything is fine I waited for work permit. But yesterday I got it so everything is in move again.<br /><br />About code this is usage of queue:<br /><br />bool CCommandBuffer::execute( void )<br />{<br /> // There is nothing to do so exit.<br /> if (isEmpty())<br /> {<br /> return false;<br /> }<br /><br /> uint8* readTo = m_MemoryWritePtr;<br /><br /> while(m_MemoryReadPtr != readTo)<br /> {<br /> uint8* readMem = m_MemoryReadPtr;<br /><br /> ECommands::ENUM cmd = (ECommands::ENUM)*(m_MemoryReadPtr++);<br /><br /> if (execCommand(cmd, m_MemoryReadPtr))<br /> {<br /> // WRAP COMMAND<br /> m_MemoryReadPtr = m_Memory;<br /> }<br /> else<br /> {<br /> m_MemoryReadPtr += getCmdSize(cmd);<br /> }<br /> }<br /><br /> return true;<br />}<br /><br />As you see [cmd_id] is single byte containing enum. [cmd_data] is SCommand<T>::SData (example in post). <br /><br />Captcha disabled :]Angelushttps://www.blogger.com/profile/02218727575338098906noreply@blogger.comtag:blogger.com,1999:blog-4447090642049340023.post-61161185570663541812013-09-26T04:18:08.710-07:002013-09-26T04:18:08.710-07:00Why are you still in Poland? Something went wrong?...Why are you still in Poland? Something went wrong?<br /><br />Jesus, disable that damn captcha :OAnonymoushttps://www.blogger.com/profile/17641927094685224341noreply@blogger.comtag:blogger.com,1999:blog-4447090642049340023.post-26410506984059195692013-09-26T04:16:43.102-07:002013-09-26T04:16:43.102-07:00Btw, paste some more code to your tech posts (even...Btw, paste some more code to your tech posts (even pseudo one). This makes more sense to programmers like myself :)<br /><br />What's inside [cmd_data], is it a pointer to some object? I assume that cmd_id is a identifier (ENum) of particular command. Does it all mean that you have unified data size for all possible commands? (i.e. union like?)<br />Anonymoushttps://www.blogger.com/profile/17641927094685224341noreply@blogger.comtag:blogger.com,1999:blog-4447090642049340023.post-91129453483130317952013-09-26T04:00:58.072-07:002013-09-26T04:00:58.072-07:00Hi :] right now I'm still in Poland.
About th...Hi :] right now I'm still in Poland.<br /><br />About this solution for sure we lose validation on compilation level and complicate a little adding new commands this facts I'm sure. But I think about the rest. <br /><br />Maybe I will give some little more detailed background : this queue is very low level and use continues memory allocated on initialization. You can see it as ring buffer with format [cmd_id][cmd_data]...... Right now I think how efficient and nicely build usage of your case and if it would look better than actual implementation use it in code.<br /><br />About comments this is standard blogspot which I think isn't prepared for advance C++ code. I will look if anything can be done about it.Angelushttps://www.blogger.com/profile/02218727575338098906noreply@blogger.comtag:blogger.com,1999:blog-4447090642049340023.post-56796684759498645582013-09-26T03:34:48.109-07:002013-09-26T03:34:48.109-07:00Heh, it wasn't me its just template brackets a...Heh, it wasn't me its just template brackets are considered to be HTML tag. Woot!<br /><br />SCommand_BuildShaderProgram is a template argumant for SCommandBase ;)<br /><br />class SCommand_BuildShaderProgram : SCommandBase(SCommand_BuildShaderProgram)<br />{<br /> (...)<br />}Anonymoushttps://www.blogger.com/profile/17641927094685224341noreply@blogger.comtag:blogger.com,1999:blog-4447090642049340023.post-57721515744551593762013-09-26T03:30:54.993-07:002013-09-26T03:30:54.993-07:00Oups forgot to add template argumant in the SComma...Oups forgot to add template argumant in the SCommand_BuildShaderProgram class. Should be:<br />class SCommand_BuildShaderProgram : SCommandBase<br />{<br /> (...)<br />}<br /><br />ofc. ;)Anonymoushttps://www.blogger.com/profile/17641927094685224341noreply@blogger.comtag:blogger.com,1999:blog-4447090642049340023.post-84784134473414761842013-09-26T00:37:57.852-07:002013-09-26T00:37:57.852-07:00P.S. Miss our tech talks ;)
Concider chananging yo...P.S. Miss our tech talks ;)<br />Concider chananging your blog engine to something more user friendly. Posts reply are terrible right now ;)Anonymoushttps://www.blogger.com/profile/17641927094685224341noreply@blogger.comtag:blogger.com,1999:blog-4447090642049340023.post-84264027781390771752013-09-26T00:27:11.823-07:002013-09-26T00:27:11.823-07:00Hey Greg. Hope you are doing fine in the maple lea...Hey Greg. Hope you are doing fine in the maple leaf country ;)<br /><br />Have you heard about CRTP pattern? I think you could use it in this scenario some way. Maybe it will make your code a little bit clearer ;)<br /><br />First let's define an interface for all your commands:<br /><br />class ICommand<br />{<br />public:<br /> virtual ~Command() {}<br /> virtual void executeCommand() const = 0;<br />};<br /><br />Then create class that will implement interface above.<br />Since CRTP pattern allows to make a method call from future derived classes you can simply static cast to known template argument to call appropirate implementation of execute.<br /><br />template <br />class SCommandBase : public ICommand<br />{<br />public:<br /> void executeCommand(T* pCommand)<br /> {<br /> static_cast(this)->execute();<br /> }<br />};<br /><br />Now lest make some commands that inherit from our CRTP base class.<br /><br />class SCommand_BuildShaderProgram : SCommandBase<br />{<br />public:<br /> void execute()<br /> {<br /> program->build();<br /> }<br /><br /><br />private:<br /> // This can be particulary anything you want<br /> CShaderProgram* program;<br />};<br /><br />Now you can store collection of ICommand derived classes an simply call their executeCommand method to implicitly call execute method from your Command concrete classes.<br />And everythng without unneccery data bloat and polymorphism overhead.<br /><br />Good day :)Anonymoushttps://www.blogger.com/profile/17641927094685224341noreply@blogger.com