Skip to content

Instantly share code, notes, and snippets.

@floooh
floooh / NetClient.cc
Created January 18, 2017 16:07
NetClient.h (emscripten/osx/win)
//------------------------------------------------------------------------------
// NetClient.cc
//------------------------------------------------------------------------------
#if ORYOL_WINDOWS
#define _WINSOCK_DEPRECATED_NO_WARNINGS (1)
#include <WinSock2.h>
typedef int ssize_t;
#endif
#if ORYOL_POSIX
==== Building flatbuffers (release64) ====
==== Building protocol (release64) ====
Running pre-build commands
../bin/x64_release/flatbuffers/flatc --cpp --scoped-enums -o ../../../code/protocol/ ../../../code/protocol/protocol.fbs
==== Building net (release64) ====
protocol_message.cpp
tcp_client.cpp
In file included from ../../../code/net/tcp_client.cpp:11:
In file included from ../../../code/net/tcp_client.h:15:
In file included from ../../../code/thirdparty/asio/asio.hpp:19:
@floooh
floooh / CMakeLists.txt
Last active August 11, 2019 17:30
copy asset files as fips code-gen job
# a code-gen job must be added to the application's CMakeLists.txt through a call to fips_generate()
fips_begin_app(dragons windowed)
fips_src(.)
fips_generate(files.yml TYPE filecopy OUT_OF_SOURCE ARGS "{ deploy_dir: \"${FIPS_PROJECT_DEPLOY_DIR}\" }")
# REMOVE THIS: n3h5_files(files.yml)
fips_deps(emsctest)
fips_end_app()
@floooh
floooh / oryol_game_loop.md
Last active May 8, 2017 19:42
How the Oryol game loop and event handling works

Execution starts in a macro "OryolMain()", this contains the platform's main() function, creates an App-object and calls the App::StartMainLoop() method. There are 3 macro version, one for Windows (containing WinMain()), one for Android (android_main()) and all other platforms (vanilla main()):

https://github.com/floooh/oryol/blob/master/code/Modules/Core/Main.h

https://github.com/floooh/oryol/blob/master/code/Modules/Core/App.cc#L66

The App::StartMainLoop() has further platform-specific handling, on platforms where

@floooh
floooh / Wireframe.cc
Last active June 16, 2017 14:05
A complete wireframe debug renderer for Oryol
//------------------------------------------------------------------------------
// Wireframe.cc
//------------------------------------------------------------------------------
#include "Pre.h"
#include "Wireframe.h"
#include "Gfx/Gfx.h"
#include "shaders.h"
namespace Oryol {
// component pools...
ComponentPool<TransformComponent> Transform;
ComponentPool<AudioComponent> Audio;
ComponentPool<RenderComponent> Render;
// component pools would be registered somewhere central...
ComponentPoolRegistry.Register(Tansform);
...
// creating an entity is just picking a free Id, which serves
@floooh
floooh / cmake_funcs.txt
Last active September 26, 2020 21:51
Fips generator example to copy files during build process
To invoke the generator from the cmake target you should define a helper macro in you project root's "fips-include.cmake" file:
macro(copy_files yml_file)
fips_generate(FROM ${yml_file}
TYPE filecopy
OUT_OF_SOURCE
ARGS "{ deploy_dir: \"${FIPS_PROJECT_DEPLOY_DIR}\" }")
endmacro()
In your cmake target definition you would then use this like:
(1) change root URL to localhost, port 8000 (8080 for node's http-server), don't forget
the trailing slash:
ioSetup.Assigns.Add("orb:", "http://127.0.0.1:8000/"); // ORYOL_SAMPLE_URL);
(2) in oryol-samples/data, start a local HTTP server:
~/p/o/data ❯❯❯ pwd
/Users/floh/projects/oryol-samples/data
~/p/o/data ❯❯❯ python -m SimpleHTTPServer
@floooh
floooh / gist:360e884ea45c9868039c9ddb1343750d
Created December 5, 2017 13:01
emscripten/posix socket client example
//------------------------------------------------------------------------------
// NetClient.cc
//------------------------------------------------------------------------------
#if ORYOL_WINDOWS
#define _WINSOCK_DEPRECATED_NO_WARNINGS (1)
#include <WinSock2.h>
typedef int ssize_t;
#endif
#if ORYOL_POSIX
@floooh
floooh / imgui_buffer_update.md
Last active February 9, 2022 12:26
How I update vertex/index buffers for Dear Imgui

My Dear Imgui render loop looks a bit unusual because I want to reduce calls to WebGL as much as possible, especially buffer update calls.

This means:

  • only one buffer each for all per-frame vertex- and index-data
  • only one update call each per frame for vertex- and index-data (with my own double-buffering, since buffer-orphaning doesn't work on WebGL, and with this I'm also independent from any 'under-the-hood' magic a GL driver might or might not perform)