Jump to content

  • Log In with Google      Sign In   
  • Create Account

Washu

Member Since 24 Mar 2001
Offline Last Active Today, 01:09 AM

#5290154 Is it C# Territory?

Posted by Washu on 04 May 2016 - 05:02 PM

Your good reason is "We have hundreds of thousands of man hours invested in our giant aging C++ code base, thus we'll be keeping that around. kthxbye."




#5260195 Return type of arbitrary function

Posted by Washu on 02 November 2015 - 02:48 PM

#include <iostream>
#include <type_traits>

template<class C, class T, class... Args>
T result_of(T (C::*)(Args...)) {
    return T();
}

template<typename T>
class S {
public:
    using ResultType = decltype(result_of(&T::C));
};

class A {
public:
    int C(int) {
        return 0;
    }
};

class B {
public:
    float C(float, float) {
        return 0;
    }
};

int main() {
    S<A>::ResultType x;
    std::cout<<typeid(x).name()<<std::endl;

    S<B>::ResultType y;
    std::cout << typeid(y).name() << std::endl;
}



#5259304 Game development with assembly. Where to start?

Posted by Washu on 27 October 2015 - 12:28 PM

...something fun like learn assembly. However displaying text on a console wasn't very exciting for me.


Writing assembly doesn't get much more exciting than that! It does get more tedious and much more difficult, however. You do graphics in the exact same way as you'd do it in C - just with more effort to manage the same data and make the same calls.


Pretty much. I mean... here's a simple triangle example that I wrote a while back...
http://www.gamedev.net/blog/32/entry-2254711-oh-god-it-gets-even-worse/
.586
.model flat, stdcall
option casemap :none

includelib <d3d11.lib>
includelib <d3dcompiler.lib>

@ArgRev MACRO arglist:REQ
    LOCAL txt, arg
    txt TEXTEQU <>
%   FOR arg, <arglist>
        txt CATSTR <arg>, <,>, txt
    ENDM

    txt SUBSTR  txt, 1, @SizeStr( %txt ) - 1
    txt CATSTR  <!<>, txt, <!>>
    EXITM txt
ENDM

INVOKEC    MACRO comObject, methodNumber, args:VARARG
    LOCAL txt
    IFNB <args>
%       FOR arg, @ArgRev( <args> )
            push arg
        ENDM
    ENDIF
    mov  ecx, dword ptr [comObject]
    push ecx
    mov  eax, [ecx]
    mov  edx, dword ptr [eax + methodNumber];
    call edx
ENDM

RELEASE    MACRO comObject
     LOCAL skip
     cmp  comObject, 0
     jz  skip
     INVOKEC comObject, IUnknown_Release
skip:
ENDM

DEFINEGUID          MACRO name, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11
name    DD _1
        DW _2
        DW _3
        DB _4
        DB _5
        DB _6
        DB _7
        DB _8
        DB _9
        DB _10
        DB _11
ENDM

ExitProcess                     PROTO stdcall :DWORD
MessageBoxA                     PROTO stdcall :DWORD, :DWORD, :DWORD, :DWORD
RegisterClassExA                PROTO stdcall :DWORD
GetModuleHandleA                PROTO stdcall :DWORD
DefWindowProcA                  PROTO stdcall :DWORD, :DWORD, :DWORD, :DWORD
CreateWindowExA                 PROTO stdcall :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD
PostQuitMessage                 PROTO stdcall :DWORD
ShowWindow                      PROTO stdcall :DWORD, :DWORD
UpdateWindow                    PROTO stdcall :DWORD
PeekMessageA                    PROTO stdcall :DWORD, :DWORD, :DWORD, :DWORD, :DWORD
TranslateMessage                PROTO stdcall :DWORD
DispatchMessageA                PROTO stdcall :DWORD
D3D11CreateDeviceAndSwapChain   PROTO stdcall :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD
D3DCompile                      PROTO stdcall :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD
D3DGetInputSignatureBlob        PROTO stdcall :DWORD, :DWORD, :DWORD

POINT                   STRUC 4
    x                      DWORD ?
    y                      DWORD ?
POINT                   ENDS

MSG                     STRUC 4
    hwnd                   DWORD ?
    message                DWORD ?
    wparam                 WORD  ?
    lparam                 DWORD ?
    time                   DWORD ?
    point                  POINT <>
MSG                     ENDS

WNDCLASSEX              STRUC 4
    cbSize                 DWORD SIZEOF(WNDCLASSEX)
    style                  DWORD CW_VREDRAW OR CW_HREDRAW OR CW_OWNDC
    lpfnWndProc            DWORD WndProc
    cbClsExtra             DWORD 0
    cbWndExtra             DWORD 0
    hInstance              DWORD ?
    hIcon                  DWORD 0
    hCursor                DWORD 0
    hbrBackground          DWORD COLOR_BACKGROUND
    lpszMenuName           DWORD 0
    lpszClassName          DWORD className
    hIconSm                DWORD 0
WNDCLASSEX              ENDS

DXGI_RATIONAL  STRUC 4
    numerator              DWORD ?
    denominator            DWORD ?
DXGI_RATIONAL           ENDS

DXGI_MODE_DESC          STRUC 4
    w                      DWORD 800
    h                      DWORD 600
    refreshRate            DXGI_RATIONAL <1, 60>
    format                 DWORD DXGI_FORMAT_R8G8B8A8_UNORM
    scanLineOrder          DWORD 0
    scaling                DWORD 0
DXGI_MODE_DESC          ENDS

DXGI_SWAP_CHAIN_DESC    STRUC 4
    bufferDesc             DXGI_MODE_DESC <>
    sampleDesc             DXGI_RATIONAL <1, 0>
    usage                  DWORD 20h OR 40h
    bufferCount            DWORD 2
    window                 DWORD ?
    windowed               DWORD 1
    swapEffect             DWORD 0
    flags                  DWORD 0
DXGI_SWAP_CHAIN_DESC    ENDS

D3D11_BUFFER_DESC       STRUC 4
    byteWidth               DWORD ?
    usage                   DWORD ?
    bindFlags               DWORD ?
    cpuAccessFlags          DWORD ?
    miscFlags               DWORD ?
    structByteStride        DWORD ?
D3D11_BUFFER_DESC       ENDS

D3D11_SUBRESOURCE_DATA  STRUC 4
    srcData                 DWORD ?
    scrap1                  DWORD 0
    scrap2                  DWORD 0
D3D11_SUBRESOURCE_DATA  ENDS

D3D11_INPUT_ELEMENT_DESC STRUC 4
    semanticName            DWORD ?
    semanticIndex           DWORD ?
    format                  DWORD ?
    slot                    DWORD ?
    byteOffset              DWORD ?
    slotClass               DWORD ?
    dataStepRate            DWORD ?
D3D11_INPUT_ELEMENT_DESC ENDS

D3D11_VIEWPORT          STRUC 4
    topLeftX                REAL4 0.0
    topLeftY                REAL4 0.0
    windowWidth             REAL4 800.0
    windowHeight            REAL4 600.0
    minDepth                REAL4 0.0
    maxDepth                REAL4 1.0
D3D11_VIEWPORT          ENDS

MB_OK                       EQU 0
SW_SHOW                     EQU 5
CW_VREDRAW                  EQU 1
CW_HREDRAW                  EQU 2
CW_OWNDC                    EQU 20h
COLOR_BACKGROUND            EQU 1
WS_OVERLAPPED               EQU 00000000h
WS_MINIMIZEBOX              EQU 00020000h
WS_MAXIMIZEBOX              EQU 00020000h
WS_SYSMENU                  EQU 00080000h
WS_THICKFRAME               EQU 00040000h
WS_CAPTION                  EQU 00C00000h
WS_OVERLAPPEDWINDOW         EQU WS_OVERLAPPED OR WS_MINIMIZEBOX OR WS_MAXIMIZEBOX OR WS_SYSMENU OR WS_THICKFRAME OR WS_CAPTION
WM_QUIT                     EQU 0012h

D3D_DRIVER_TYPE_UNKNOWN             EQU 0
D3D_DRIVER_TYPE_HARDWARE            EQU ( D3D_DRIVER_TYPE_UNKNOWN + 1 )
D3D11_CREATE_DEVICE_SINGLETHREADED  EQU 1
D3D_FEATURE_LEVEL_9_1               EQU 09100h
D3D_FEATURE_LEVEL_9_2               EQU 09200h
D3D_FEATURE_LEVEL_9_3               EQU 09300h
D3D_FEATURE_LEVEL_10_0              EQU 0a000h
D3D_FEATURE_LEVEL_10_1              EQU 0a100h
D3D_FEATURE_LEVEL_11_0              EQU 0b000h
DXGI_FORMAT_R8G8B8A8_UNORM          EQU 28
DXGI_FORMAT_R32G32B32A32_FLOAT      EQU 2
D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST EQU 4

IUnknown_QueryInterface     EQU 0h
IUnknown_AddRef             EQU 4h
IUnknown_Release            EQU 8h

ID3D10Blob_GetBufferData    EQU IUnknown_Release + 4
ID3D10Blob_GetBufferSize    EQU IUnknown_Release + 8

IDXGISwapChain_GetBuffer    EQU 24h
IDXGISwapChain_Present      EQU 20h

ID3D11Device_CreateRTView   EQU 24h
ID3D11Device_CreateVS       EQU 30h
ID3D11Device_CreatePS       EQU 3Ch
ID3D11Device_CreateBuffer   EQU 0Ch
ID3D11Device_CreateLayout   EQU 2Ch

ID3D11Context_ClearRTView   EQU 0C8h
ID3D11Context_OMSetRT       EQU 84h
ID3D11Context_IASetLayout   EQU 44h
ID3D11Context_VSSetShader   EQU 2Ch
ID3D11Context_PSSetShader   EQU 24h
ID3D11Context_IASetPrimTop  EQU 60h
ID3D11Context_RSSetViewport EQU 0B0h
ID3D11Context_IASetVertBuff EQU 48h
ID3D11Context_Draw          EQU 34h

.data
msgTitle    DB "Oh shit son!", 0
regFail     DB "Failed to register window class.", 0
cwFail      DB "Failed to create window.", 0
showFail    DB "Failed to show window.", 0
updateFail  DB "Failed to update window.", 0
d3d11Fail1  DB "Failed to create D3D11 device.", 0
d3d11Fail2  DB "Failed to get back buffer from swap chain.", 0
d3d11Fail3  DB "Failed to create render target.", 0
d3d11Fail4  DB "Failed to compile pixel shader.", 0
d3d11Fail5  DB "Failed to compile vertex shader.", 0
d3d11Fail6  DB "Failed to get vertex shader layout.", 0
d3d11Fail7  DB "Failed to create vertex buffer.", 0
d3d11Fail8  DB "Failed to create input layout.", 0
d3d11Fail9  DB "Failed to create shader resource.", 0

messageIdx  DD regFail, cwFail, showFail, updateFail, d3d11Fail1, d3d11Fail2, d3d11Fail3, d3d11Fail4, d3d11Fail5, d3d11Fail6, d3d11Fail7, d3d11Fail8, d3d11Fail9

className   DB "TestClass", 0
windowTitle DB "My Window", 0
wndClass    WNDCLASSEX <>
swapDesc    DXGI_SWAP_CHAIN_DESC <>
featureLvl  DD D3D_FEATURE_LEVEL_11_0, D3D_FEATURE_LEVEL_10_1, D3D_FEATURE_LEVEL_10_0, D3D_FEATURE_LEVEL_9_3
swapChain   DD 0
device      DD 0
newFeatLvl  DD 0
context     DD 0

blackColor  DD 0, 0, 0, 0
backBuffer  DD 0
view        DD 0
DEFINEGUID  ID3D11Texture2D_GUID, 6f15aaf2h, 0d208h, 04e89h, 09ah, 0b4h, 048h, 095h, 035h, 0d3h, 04fh, 09Ch

viewport    D3D11_VIEWPORT <>

psSource    DB "struct VS_IN { float4 pos : POSITION; float4 col : COLOR; }; struct PS_IN { float4 pos : SV_POSITION; float4 col : COLOR; }; float4 PS( PS_IN input ) : SV_Target { return input.col; }", 0
psSourceLen DD $ - OFFSET psSource
psTarget    DB "ps_5_0", 0
psEntry     DB "PS", 0

vsSource    DB"struct VS_IN { float4 pos : POSITION; float4 col : COLOR; }; struct PS_IN { float4 pos : SV_POSITION; float4 col : COLOR; }; PS_IN VS( VS_IN input ) { PS_IN output = (PS_IN)0; output.pos = input.pos; output.col = input.col; return output; }", 0
vsSourceLen DD $ - OFFSET vsSource
vsTarget    DB "vs_5_0", 0
vsEntry     DB "VS", 0

vertData    REAL4 0.0, 0.5, 0.5, 1.0, 1.0, 0.0, 0.0, 1.0
            REAL4 0.5f, -0.5f, 0.5f, 1.0, 0.0, 1.0, 0.0, 1.0
            REAL4 -0.5f, -0.5f, 0.5f, 1.0, 0.0, 0.0, 1.0, 1.0

vertDesc    D3D11_BUFFER_DESC < 96, 0, 1, 0, 0, 0 >
vertSub     D3D11_SUBRESOURCE_DATA < vertData >
vertDescPos DB "POSITION", 0
vertDescCol DB "COLOR", 0
vertLayout  D3D11_INPUT_ELEMENT_DESC < OFFSET vertDescPos, 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, 0, 0 >
            D3D11_INPUT_ELEMENT_DESC < OFFSET vertDescCol, 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 16, 0, 0 >
vertStride  DD 32
vertOffset  DD 0

vertBuff    DD 0
inputLayout DD 0
psShader    DD 0
psBlob      DD 0
psBlobErr   DD 0
vsShader    DD 0
vsBlob      DD 0
vsBlobErr   DD 0
layoutBlob  DD 0
vsError     DD 0
blobPtr     DD 0
blobSize    DD 0

.code
WndProc  PROC stdcall hwnd:DWORD, msg:DWORD, wparam:WORD, lparam:DWORD
    cmp    msg, 2
    jnz    done
    INVOKE PostQuitMessage, 0
    xor    eax, eax
    ret
done:
    INVOKE DefWindowProcA, hwnd, msg, wparam, lparam
    ret;
WndProc  ENDP

main  PROC
    LOCAL  hwnd:DWORD
    LOCAL  hmodule:DWORD
    LOCAL  msg:MSG

    INVOKE GetModuleHandleA, 0
    mov    hmodule, eax
    mov    wndClass.hInstance, eax

    INVOKE RegisterClassExA, OFFSET wndClass
    cmp    eax, 0
    mov    eax, 0
    jz     error

    INVOKE CreateWindowExA, 0, OFFSET className, OFFSET windowTitle, WS_OVERLAPPEDWINDOW, 0, 0, 800, 600, 0, 0, hmodule, 0
    mov    hwnd, eax
    cmp    eax, 0
    mov    eax, 1
    jz     error

    INVOKE ShowWindow, hwnd, SW_SHOW
    INVOKE UpdateWindow, hwnd
    cmp    eax, 0
    mov    eax, 3
    jz     error

    mov    eax, hwnd
    mov    swapDesc.window, eax

    INVOKE D3D11CreateDeviceAndSwapChain, 0, D3D_DRIVER_TYPE_HARDWARE, 0, 0, OFFSET featureLvl, 4, 7, OFFSET swapDesc, OFFSET swapChain, OFFSET device, OFFSET newFeatLvl, OFFSET context
    cmp    eax, 0
    mov    eax, 4
    jnz    error

    INVOKEC swapChain, IDXGISwapChain_GetBuffer, 0, OFFSET ID3D11Texture2D_GUID, OFFSET backBuffer
    cmp    eax, 0
    mov    eax, 5
    jnz    error

    INVOKEC device, ID3D11Device_CreateRTView, dword ptr [backBuffer], 0, OFFSET view
    cmp    eax, 0
    mov    eax, 6
    jnz    error

    INVOKE D3DCompile, OFFSET psSource, psSourceLen, 0, 0, 0, OFFSET psEntry, OFFSET psTarget, 0, 0, OFFSET psBlob, OFFSET psBlobErr
    cmp    eax, 0
    mov    eax, 7
    jnz    error

    INVOKE D3DCompile, OFFSET vsSource, vsSourceLen, 0, 0, 0, OFFSET vsEntry, OFFSET vsTarget, 0, 0, OFFSET vsBlob, OFFSET vsBlobErr
    cmp    eax, 0
    mov    eax, 8
    jnz    error

    INVOKEC vsBlob, ID3D10Blob_GetBufferData
    mov    blobPtr, eax

    INVOKEC vsBlob, ID3D10Blob_GetBufferSize
    mov    blobSize, eax

    INVOKE D3DGetInputSignatureBlob, blobPtr, blobSize, OFFSET layoutBlob
    cmp    eax, 0
    mov    eax, 9
    jnz    error

    INVOKEC device, ID3D11Device_CreateBuffer, OFFSET vertDesc, OFFSET vertSub, OFFSET vertBuff
    cmp    eax, 0
    mov    eax, 10
    jnz    error

    INVOKEC layoutBlob, ID3D10Blob_GetBufferSize
    mov    blobSize, eax

    INVOKEC layoutBlob, ID3D10Blob_GetBufferData

    INVOKEC device, ID3D11Device_CreateLayout, OFFSET vertLayout, 2, eax, blobSize, OFFSET inputLayout
    cmp    eax, 0
    mov    eax, 11
    jnz    error

    INVOKEC vsBlob, ID3D10Blob_GetBufferData
    mov    blobPtr, eax

    INVOKEC vsBlob, ID3D10Blob_GetBufferSize

    INVOKEC device, ID3D11Device_CreateVS, blobPtr, eax, 0, OFFSET vsShader
    cmp    eax, 0
    mov    eax, 12
    jnz    error

    INVOKEC psBlob, ID3D10Blob_GetBufferData
    mov    blobPtr, eax

    INVOKEC psBlob, ID3D10Blob_GetBufferSize

    INVOKEC device, ID3D11Device_CreatePS, blobPtr, eax, 0, OFFSET psShader
    cmp    eax, 0
    mov    eax, 12
    jnz    error

    RELEASE psBlob
    RELEASE vsBlob
    RELEASE layoutBlob

    INVOKEC context, ID3D11Context_OMSetRT, 1, OFFSET view, 0
    INVOKEC context, ID3D11Context_IASetLayout, inputLayout
    INVOKEC context, ID3D11Context_VSSetShader, vsShader, 0, 0
    INVOKEC context, ID3D11Context_PSSetShader, psShader, 0, 0
    INVOKEC context, ID3D11Context_IASetPrimTop, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST
    INVOKEC context, ID3D11Context_RSSetViewport, 1, OFFSET viewport
    INVOKEC context, ID3D11Context_IASetVertBuff, 0, 1, OFFSET vertBuff, OFFSET vertStride, OFFSET vertOffset
gameLoop:
msgLoop:
    INVOKE PeekMessageA, ADDR msg, 0, 0, 0, 1
    cmp    eax, 0
    jz     gameNext
    cmp    msg.message, WM_QUIT
    jz     done
    INVOKE TranslateMessage, ADDR msg
    INVOKE DispatchMessageA, ADDR msg
    jmp    msgLoop
gameNext:
    INVOKEC context, ID3D11Context_ClearRTView, view, OFFSET blackColor
    INVOKEC context, ID3D11Context_Draw, 3, 0
    INVOKEC swapChain, IDXGISwapChain_Present, 0, 0
    jmp    gameLoop

done:
    RELEASE view
    RELEASE backBuffer
    RELEASE swapChain
    RELEASE device
    RELEASE context
    RELEASE vsShader
    RELEASE psShader
    RELEASE inputLayout
    RELEASE vertBuff
    INVOKE ExitProcess, eax
    ret
error:
    mov    eax, messageIdx[eax*4]
    INVOKE MessageBoxA, 0, eax, ADDR msgTitle, MB_OK
    jmp done
main  ENDP
END main



#5257959 Does calling ~myclass() (destructor) deletes the object?

Posted by Washu on 19 October 2015 - 01:50 PM

	if (pdata != NULL) delete [] pdata;


If you do that, do this:
 
if (pdata != NULL)
{
    delete[] pdata;
    pdata = NULL;
}
In other words, make sure that your object is in a valid state in case someone calls kill twice, or kill once and delete once.

if you do that... do this:
    delete[] pdata;
    pdata = NULL;
Hooray! A useless null check is gone.


#5257957 Does calling ~myclass() (destructor) deletes the object?

Posted by Washu on 19 October 2015 - 01:45 PM

I had a strange problem i was appending an array using delete/new
 
but after creation of new array i had to put the structs in it (texture loading- whenever i loaded texture that wasnt 256x256 i had to resize it -> ther i called mytexture[i].~TGLTexture(); //it seems that was the problem i had to write another function that wasnt named ~TGLTexture() with the exact code.
 
So my question is: does calling a destructor w/o delete, deletes the object? it seems that yes but i didint find anythig on the net about it

No. Construction and destruction are two entirely separate things in C++.

You should never call the destructor directly. Always use delete.

There are plenty of reasons to call destructors directly. Placement newed objects for instance. In collections, etc.


#5254901 Why did COD: AW move every file into the same folder where .exe is?

Posted by Washu on 30 September 2015 - 06:24 PM

I do have an issue with directories sometimes, it's "\\" or "\" or "/"  ......  agghhh

 
Just FYI, Windows has allowed forward slashes "/" as directory delimiters for a long time.

Since DOS 1.0.

As for paths in games... Why would you ever take a path from a designer and not normalize it. If it's a programmer doing it, then you should have better path creation tools and/or normalize them.

Frankly, if you're hard coding paths into your runtime... You're going to have other issues than just platform porting.


#5254878 How can I make a text parser?

Posted by Washu on 30 September 2015 - 03:09 PM

Recursive descent parsers are pretty easy to implement.
 
Generally if you can make a game you shouldn't have a problem understanding simple RD parsers.
 
Personally for anything more advanced than a key value pair format, I'd be tempted to use YACC and BISON and friends and not reinvent the whole car never mind it's wheel...

Personally... If I'm going to be using something more advanced than is necessary to parse json/xml using an off the shelf parser...
It suggests you should probably plug in a proper scripting solution (lua, pythong, etc), instead of designing your own language. Stick to standard formats (like JSON) for data. It'll save you a ton of useless wasted effort.


#5253476 Best language for solving diamond problem & is this a good idea for multi...

Posted by Washu on 22 September 2015 - 11:06 AM

I suspect most people here will suggest trying composition instead of using inheritance at all. It's easier to get what you want, and you don't have to fight with the language.

QFE.

Most cases where people encounter the diamond problem, in my experience, are cases where composition was more likely to be the appropriate choice.


#5252728 Why std::copy is faster than std::memcpy ?

Posted by Washu on 17 September 2015 - 01:15 PM

Nice to know, but since the compiler optimize for memcpy, it's safer to always use memcpy, true ?
About the timer, good point, I should stop to use SDL timer and implement a custom one with better precision.

If you are in C++, you should use std::copy. memcpy is dangerous, it doesn't invoke copy or move constructors, and completely ignores type safety.


#5251800 Why std::copy is faster than std::memcpy ?

Posted by Washu on 11 September 2015 - 06:43 PM

First things first: That's not how most std::copy implementations work.

 

If you actually look at it you will see a lot of them use compile time type deduction to optimize the amount of work they need to do. Furthermore, as they're templates and fairly small, they have a high chance of being inlined. Lastly, due to the fact that the compiler has exact information about the size of the objects it can explicitly optimize the copy for your type. Lastly, a lot of times, if copy can deduce the point is a pointer, then it can simply delegate to memmove.

 

memcpy tends to be located in the msvcrt dll, and as such will typically not be inlined (LTCG can do this though). It also is quite a bit more complex as it does not actually know what you're going to be passing into it at compile time, and thus has to do more work to efficiently move things around.

 

All of that being said, in general the two should perform roughly the same.




#5244233 C++ Operator Overloading: Bitwise Operators & If-Check

Posted by Washu on 02 August 2015 - 10:21 PM


I suspect it was supposed to be (f & uf) != 0, since the other version is definitely not equivalent. It prevents the implicit cast from unsigned to bool and all the potential compiler warnings that come with it (in VS it's usually something about runtime performance).

 

I do not know what his intention was, however typically if you're testing flags and you want to ensure that all of the flags you are testing are set, you want (flags & flagsToTestFor) == something, as otherwise only having some of the flags in flagsToTestFor set can still return non-zero.




#5241420 Multithreading problem when reloading a D3D model on user input

Posted by Washu on 19 July 2015 - 02:44 PM

Lets get started here:
 

  1. Why aren't you using std::thread?
  2. The function you're passing to CreateThread MUST be __stdcall (WINAPI). Microsoft goes to a lot of effort to detect when people do bad things like pass in cdecl or similar calling conventions. All that work is overhead you inherit when you do it wrong.
  3. Having a function called "createThreadFunction" that takes a VOID POINTER as a function parameter is just flat out wrong. Don't do this.
  4. bool, and std::atomic<bool> are not mutexes. You can use std::mutex if you need mutex like behavior.
  5. While std::atomic<bool> does enforce a memory barrier, it does not prevent multiple pieces of the same code from running at once.



#5240071 D3DXCreateTextureFromFileInMemoryEx in a thread failing

Posted by Washu on 13 July 2015 - 08:26 AM

Did you create your device with D3DCREATE_MULTITHREADED specified?


#5239794 [SlimDX] Information on the history of SlimDX

Posted by Washu on 11 July 2015 - 02:31 PM

I ultimately solved the problem through the aforementioned object table, a tool that in retrospect I still have extremely mixed feelings about. In the vast majority of cases, it actually does its job quietly and magnificently, as well as enabling some very useful debugging techniques. But in the bad cases, it gets really problematic. As Josh noted, we had not planned on using that design again if we were going to take another crack at rearchitecting the whole library.


The object table was both a great solution, and the worst possible one.

For the vast majority of the simple use cases for DirectX objects, the object table solved the issue trivially and cleanly, and made lifetime management in C# enjoyable. On the other hand, when things got a bit less trivial it very quickly devolved to a point where you had to write your own lifetime management code in C#, simply because we were not exposing AddRef/Release semantics in C#. Ultimately, I think we should have gone for a two fold approach of having an object manager and the ability to expose AddRef/Release semantics with it being a choice of one or the other. Non-trivial to implement, sure, but much less annoying in those non-trivial use cases.


#5239790 [SlimDX] Information on the history of SlimDX

Posted by Washu on 11 July 2015 - 02:16 PM

Building documentation was oddly a real pain. MS went to a lot of trouble to build this comment documentation stuff into VS, but apparently it never ever occurred to them that, gee, maybe somebody else would want to be able to publish miniature forms of MSDN for their work. Eventually Sandcastleappeared and I used that with many custom patches. In conjunction with SHFB, it works really well to make CHM documentation. It is (was?) however entirely useless for building websites. I eventually did some more custom patches and homebrewed a site with JQuery and that's what drives the current documentation.

 
On the documentation front we spent a lot of time trying to be helpful and using documentation comments for later extraction into the docs. That being said, one amusing anecdote I can recall is when MikeP and I spent several hours fixing a few hundred thousand warnings from Josh's doc comments that were qualifying member names incorrectly...
 
Sadly, I never got a mug, nor my name on a mug. Probably a good thing though.

4) Future plans
When SlimDX was built, we all had a lot more time on our hands. I want to simply hand implement (not auto gen) the SlimDX 2 design for D3D 12, roll the math library in, and call it a day. This is somewhat complicated by a few things. First, life. I have a lot of it nowadays and that's getting inconvenient. Second, at a personal level I have a lot of doubts about D3D 12's near-term viability and a lot of optimism about Vulkan, which is complicating things. I still want to do it, but I'm not in that big a hurry.


I can certainly feel you there, although the fact that DX12 is effectively to market already, as opposed to Vulkan for which we've even yet to see a working API (Mantle doesn't really count)...




PARTNERS