GameMaker/Game Dev Memes

zbox

Member
GMC Elder
When you are so good at making bad code that you are bad at making good code but it still werks.
C++:
static inline void video_thread(video_t ind, wid_t wid) {
  // MPEG-2 vidoe codec + MP2 audio codec + *.MPG = werk!
  HRESULT hr = S_OK;
  CoInitialize(NULL);
  HWND vidwin = NULL;
  RECT rect; long evCode;
  widmap.insert(std::make_pair(ind, wid));
  HWND window = (HWND)stoull(wid, nullptr, 10);
  wstring wstr_fname = widen(vidmap.find(ind)->second);
  hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void **)&pGraph);
  if (SUCCEEDED(hr)) {
    hr = pGraph->RenderFile(wstr_fname.c_str(), NULL);
    if (SUCCEEDED(hr)) {
      hr = CoCreateInstance(CLSID_VideoMixingRenderer, NULL, CLSCTX_INPROC_SERVER, IID_IBaseFilter, (void **)&pVideoRenderer);
      if (SUCCEEDED(hr)) {
        hr = pGraph->FindFilterByName(L"Video Renderer", &pVideoRenderer);
        if (SUCCEEDED(hr)) {
          hr = pVideoRenderer->QueryInterface(IID_IVMRAspectRatioControl, (void **)&pAspectRatio);
          if (SUCCEEDED(hr)) {
            hr = pAspectRatio->SetAspectRatioMode(VMR_ARMODE_LETTER_BOX);
            if (SUCCEEDED(hr)) {
              hr = pGraph->QueryInterface(IID_IVideoWindow, (void **)&pVidWin);
              if (SUCCEEDED(hr)) {
                SetWindowLongPtr(window, GWL_STYLE, GetWindowLongPtr(window, GWL_STYLE) | WS_CLIPCHILDREN | WS_CLIPSIBLINGS);
                hr = pVidWin->put_Owner((OAHWND)window);
                if (SUCCEEDED(hr)) {
                  GetClientRect(window, &rect);
                  hr = pVidWin->SetWindowPosition(0, 0, rect.right - rect.left, rect.bottom - rect.top);
                  if (SUCCEEDED(hr)) {
                    hr = pVidWin->put_WindowStyle(WS_CHILD | WS_CLIPSIBLINGS);
                    if (SUCCEEDED(hr)) {
                      hr = pVidWin->SetWindowForeground(OATRUE);
                      if (SUCCEEDED(hr)) {
                        hr = pVidWin->HideCursor(OATRUE);
                        if (SUCCEEDED(hr)) {
                          hr = pGraph->QueryInterface(IID_IMediaControl, (void **)&pControl);
                          if (SUCCEEDED(hr)) {
                            hr = pVideoRenderer->FindPin(L"VMR Input0", &pin);
                            if (SUCCEEDED(hr)) {
                              hr = pin->QueryInterface(IID_IOverlay, (void **)&pOverlay);
                              if (SUCCEEDED(hr)) {
                                hr = pGraph->QueryInterface(IID_IMediaEvent, (void **)&pEvent);
                                if (SUCCEEDED(hr)) {
                                  hr = pOverlay->GetWindowHandle(&vidwin);
                                  if (SUCCEEDED(hr)) {
                                    std::lock_guard<std::mutex> guard1(window_mutex);
                                    cwidmap.insert(std::make_pair(ind, std::to_string((unsigned long long)vidwin)));
                                    std::thread finthread(update_thread, ind);
                                    hr = pControl->Run();
                                    if (SUCCEEDED(hr)) {
                                      while (ShowCursor(false) >= 0);
                                      hr = pEvent->WaitForCompletion(INFINITE, &evCode);
                                      if (SUCCEEDED(hr)) {
                                        hr = pControl->Stop();
                                        if (SUCCEEDED(hr)) {
                                          hr = pVidWin->put_Visible(OAFALSE);
                                          if (SUCCEEDED(hr)) {
                                            pVidWin->put_Owner((OAHWND)NULL);
                                          }
                                        }
                                      }
                                      while (ShowCursor(true) < 0);
                                    }
                                    std::lock_guard<std::mutex> guard2(update_mutex);
                                    updmap[ind] = false;
                                    finthread.join();
                                  }
                                }
                              }
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  if (pEvent != NULL) { pEvent->Release(); }
  if (pControl != NULL) { pControl->Release(); }
  if (pVidWin != NULL) { pVidWin->Release(); }
  if (pAspectRatio != NULL) { pAspectRatio->Release(); }
  if (pVideoRenderer != NULL) { pVideoRenderer->Release(); }
  if (pGraph != NULL) { pGraph->Release(); }
  if (pin != NULL) { pin->Release(); }
  CoUninitialize();
}
However, those != NULL checks at the end are probably redundant as I saw no obvious sign of over-releasing going on before I added them.

This is me while using callbacks in JS before I learnt about Promises haha.

If it works it works though - bury it and hope you never have to maintain it!
 
S

Sam (Deleted User)

Guest
stackoverflow answers be like...

trololo.cpp:
C++:
#include <string>

int main () {
  std::string str = "trolololo";
  while (true) { str += "lololo"; }
  return 0;
}
compile with:
Code:
g++ trololo.cpp
run with:
Code:
./a.out
Bonus points to whoever gets the punchline.
 
Last edited by a moderator:

Yal

🐧 *penguin noises*
GMC Elder
View attachment 35629

juju has proclaimed

for legal reasons this is an edited meme and a joke I'm not actually comparing the engines pls don't start war
Incidental evidence of a big programmer blogger guy spending an entire post complaining about how bad Unity's model importer is 🦈

(Also according to the forum rules we're legally obliged to only let posts that compare engines in favor of GM remain, so it's not going to be a war as much as it'd be a firing squad)
 
S

Sam (Deleted User)

Guest
std::wstring wstr = ...
wstr.c_str()

C++:
// string to wstring
wstring widen(string str) {
  size_t wchar_count = str.size() + 1;
  vector<wchar_t> buf(wchar_count);
  return wstring { buf.data(),
    (size_t)MultiByteToWideChar(
    CP_UTF8, 0, str.c_str(), -1,
    buf.data(), (int)wchar_count) };
}

// wstring to string
string narrow(wstring wstr) {
  int nbytes = WideCharToMultiByte(CP_UTF8,
    0, wstr.c_str(), (int)wstr.length(),
    NULL, 0, NULL, NULL);
  vector<char> buf(nbytes);
  return string { buf.data(),
    (size_t)WideCharToMultiByte(
    CP_UTF8, 0, wstr.c_str(),
    (int)wstr.length(), buf.data(),
    nbytes, NULL, NULL) };
}
 

Evanski

Raccoon Lord
Forum Staff
Moderator
std::wstring wstr = ...
wstr.c_str()

C++:
// string to wstring
wstring widen(string str) {
  size_t wchar_count = str.size() + 1;
  vector<wchar_t> buf(wchar_count);
  return wstring { buf.data(),
    (size_t)MultiByteToWideChar(
    CP_UTF8, 0, str.c_str(), -1,
    buf.data(), (int)wchar_count) };
}

// wstring to string
string narrow(wstring wstr) {
  int nbytes = WideCharToMultiByte(CP_UTF8,
    0, wstr.c_str(), (int)wstr.length(),
    NULL, 0, NULL, NULL);
  vector<char> buf(nbytes);
  return string { buf.data(),
    (size_t)WideCharToMultiByte(
    CP_UTF8, 0, wstr.c_str(),
    (int)wstr.length(), buf.data(),
    nbytes, NULL, NULL) };
}
C++:
//std::back_inserter
#include <iterator>

std::wstring w;
std::copy(start_string, start_string + strlen(start_string), back_inserter(w));
const WCHAR* wide_string = w.c_str();
 
S

Sam (Deleted User)

Guest
C++:
//std::back_inserter
#include <iterator>

std::wstring w;
std::copy(start_string, start_string + strlen(start_string), back_inserter(w));
const WCHAR* wide_string = w.c_str();
Then you lose UTF-8 support :)
 
S

Sam (Deleted User)

Guest
oh, hmmm. I dont think I need it as I really only need gamemaker to pass a string to the dll that is the file location of the sound to play, which it does then hard crashes
If the user passes a sound file that has non-english characters in the full path, good luck loading the sound file at all.
 
Top