Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
build/
nob
nob.exe
nob.exe.old
nob.old
*.obj
*.mp4
*.wav
*~
Expand Down
97 changes: 86 additions & 11 deletions nob.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,43 @@
#define PANIM_DIR "./panim/"
#define PLUGS_DIR "./plugs/"


#ifdef _WIN32
#define DYNLIB_EXT ".dll"
#define OUT_FLAG "/Fe:"
#define FFMPEG_SRC "ffmpeg_windows.c"

void cflags(Nob_Cmd *cmd)
{
nob_cmd_append(cmd, "/W4", "/Z7", "/FC", "-D_CRT_SECURE_NO_WARNINGS=1","/diagnostics:caret", "/diagnostics:color");
nob_cmd_append(cmd, "-I./raylib/raylib-5.0_windows_amd64/include");
nob_cmd_append(cmd, "-I"PANIM_DIR);
nob_cmd_append(cmd, "-I.");
}

void cc(Nob_Cmd *cmd)
{
nob_cmd_append(cmd, "cl");
cflags(cmd);
}

void cxx(Nob_Cmd *cmd)
{
nob_cmd_append(cmd, "cl");
//nob_cmd_append(cmd, "-Wno-missing-field-initializers"); // Very common warning when compiling raymath.h as C++
cflags(cmd);
}
void libs(Nob_Cmd *cmd)
{
nob_cmd_append(cmd, "/link","/LIBPATH:./raylib/raylib-5.0_windows_amd64/lib/");
nob_cmd_append(cmd, "raylibdll.lib");

}
#else
#define DYNLIB_EXT ".do"
#define OUT_FLAG "-o"
#define FFMPEG_SRC "ffmpeg_linux.c"

void cflags(Nob_Cmd *cmd)
{
nob_cmd_append(cmd, "-Wall", "-Wextra", "-ggdb");
Expand All @@ -26,18 +63,20 @@ void cxx(Nob_Cmd *cmd)
nob_cmd_append(cmd, "-Wno-missing-field-initializers"); // Very common warning when compiling raymath.h as C++
cflags(cmd);
}

void libs(Nob_Cmd *cmd)
{
nob_cmd_append(cmd, "-Wl,-rpath=./raylib/raylib-5.0_linux_amd64/lib/");
nob_cmd_append(cmd, "-Wl,-rpath="PANIM_DIR);
nob_cmd_append(cmd, "-L./raylib/raylib-5.0_linux_amd64/lib");
nob_cmd_append(cmd, "-l:libraylib.so", "-lm", "-ldl", "-lpthread");
}
#endif



bool build_plug_c3(bool force, Nob_Cmd *cmd, const char *output_path, const char **source_paths, size_t source_paths_count)
{
int rebuild_is_needed = nob_needs_rebuild(nob_temp_sprintf("%s.so", output_path), source_paths, source_paths_count);
int rebuild_is_needed = nob_needs_rebuild(nob_temp_sprintf("%s"DYNLIB_EXT, output_path), source_paths, source_paths_count);
if (rebuild_is_needed < 0) return false;
if (force || rebuild_is_needed) {
// TODO: check if c3c compile even exists
Expand All @@ -57,10 +96,24 @@ bool build_plug_c(bool force, Nob_Cmd *cmd, const char *source_path, const char

if (force || rebuild_is_needed) {
cc(cmd);

#ifndef _WIN32
nob_cmd_append(cmd, "-fPIC", "-shared", "-Wl,--no-undefined");
nob_cmd_append(cmd, "-o", output_path);
#endif
nob_cmd_append(cmd, OUT_FLAG, output_path);
#ifdef _WIN32
nob_cmd_append(cmd, "/LD");
#endif
nob_cmd_append(cmd, source_path);
libs(cmd);
#ifdef _WIN32
nob_cmd_append(cmd, "/EXPORT:plug_init");
nob_cmd_append(cmd, "/EXPORT:plug_pre_reload");
nob_cmd_append(cmd, "/EXPORT:plug_post_reload");
nob_cmd_append(cmd, "/EXPORT:plug_update");
nob_cmd_append(cmd, "/EXPORT:plug_reset");
nob_cmd_append(cmd, "/EXPORT:plug_finished");
#endif
return nob_cmd_run_sync_and_reset(cmd);
}

Expand All @@ -75,10 +128,23 @@ bool build_plug_cxx(bool force, Nob_Cmd *cmd, const char *source_path, const cha

if (force || rebuild_is_needed) {
cxx(cmd);
#ifndef _WIN32
nob_cmd_append(cmd, "-fPIC", "-shared", "-Wl,--no-undefined");
nob_cmd_append(cmd, "-o", output_path);
#endif
nob_cmd_append(cmd, OUT_FLAG, output_path);
#ifdef _WIN32
nob_cmd_append(cmd, "/LD");
#endif
nob_cmd_append(cmd, source_path);
libs(cmd);
#ifdef _WIN32
nob_cmd_append(cmd, "/EXPORT:plug_init");
nob_cmd_append(cmd, "/EXPORT:plug_pre_reload");
nob_cmd_append(cmd, "/EXPORT:plug_post_reload");
nob_cmd_append(cmd, "/EXPORT:plug_update");
nob_cmd_append(cmd, "/EXPORT:plug_reset");
nob_cmd_append(cmd, "/EXPORT:plug_finished");
#endif
return nob_cmd_run_sync_and_reset(cmd);
}

Expand All @@ -93,7 +159,7 @@ bool build_exe(bool force, Nob_Cmd *cmd, const char **input_paths, size_t input_

if (force || rebuild_is_needed) {
cc(cmd);
nob_cmd_append(cmd, "-o", output_path);
nob_cmd_append(cmd, OUT_FLAG, output_path);
nob_da_append_many(cmd, input_paths, input_paths_len);
libs(cmd);
return nob_cmd_run_sync_and_reset(cmd);
Expand Down Expand Up @@ -124,11 +190,13 @@ int main(int argc, char **argv)
if (!nob_mkdir_if_not_exists(BUILD_DIR)) return 1;

Nob_Cmd cmd = {0};
if (!build_plug_c(force, &cmd, PLUGS_DIR"tm/plug.c", BUILD_DIR"libtm.so")) return 1;
if (!build_plug_c(force, &cmd, PLUGS_DIR"template/plug.c", BUILD_DIR"libtemplate.so")) return 1;
if (!build_plug_c(force, &cmd, PLUGS_DIR"squares/plug.c", BUILD_DIR"libsquare.so")) return 1;
if (!build_plug_c(force, &cmd, PLUGS_DIR"bezier/plug.c", BUILD_DIR"libbezier.so")) return 1;
if (!build_plug_cxx(force, &cmd, PLUGS_DIR"cpp/plug.cpp", BUILD_DIR"libcpp.so")) return 1;
if (!build_plug_c(force, &cmd, PLUGS_DIR"tm/plug.c", BUILD_DIR"libtm"DYNLIB_EXT)) return 1;
if (!build_plug_c(force, &cmd, PLUGS_DIR"tasklesstm/plug.c", BUILD_DIR"libtasklesstm"DYNLIB_EXT)) return 1;
if (!build_plug_c(force, &cmd, PLUGS_DIR"template/plug.c", BUILD_DIR"libtemplate"DYNLIB_EXT)) return 1;
if (!build_plug_c(force, &cmd, PLUGS_DIR"squares/plug.c", BUILD_DIR"libsquare"DYNLIB_EXT)) return 1;
if (!build_plug_c(force, &cmd, PLUGS_DIR"tasklesssquares/plug.c", BUILD_DIR"libtasklesssquare"DYNLIB_EXT)) return 1;
if (!build_plug_c(force, &cmd, PLUGS_DIR"bezier/plug.c", BUILD_DIR"libbezier"DYNLIB_EXT)) return 1;
if (!build_plug_cxx(force, &cmd, PLUGS_DIR"cpp/plug.cpp", BUILD_DIR"libcpp"DYNLIB_EXT)) return 1;
{
const char *output_path = BUILD_DIR"libc3";
const char *source_paths[] = {
Expand All @@ -142,13 +210,20 @@ int main(int argc, char **argv)
}

{
#ifdef _WIN32
const char *output_path = BUILD_DIR"panim.exe";
#else
const char *output_path = BUILD_DIR"panim";
#endif
const char *input_paths[] = {
PANIM_DIR"panim.c",
PANIM_DIR"ffmpeg_linux.c"
PANIM_DIR FFMPEG_SRC
};
size_t input_paths_len = NOB_ARRAY_LEN(input_paths);
if (!build_exe(force, &cmd, input_paths, input_paths_len, output_path)) return 1;
#ifdef _WIN32
if(!nob_copy_file("./raylib/raylib-5.0_windows_amd64/lib/raylib.dll", BUILD_DIR"raylib.dll"))return 1;
#endif
}

return 0;
Expand Down
57 changes: 57 additions & 0 deletions panim/ffmpeg_windows.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#include <assert.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>


#include <raylib.h>

#include "ffmpeg.h"

#define READ_END 0
#define WRITE_END 1

struct FFMPEG {
char dummy;
};

FFMPEG *ffmpeg_start_rendering_video(const char *output_path, size_t width, size_t height, size_t fps)
{
(void)output_path;
(void)width;
(void)height;
(void)fps;
return NULL;
}

FFMPEG *ffmpeg_start_rendering_audio(const char *output_path)
{
(void)output_path;
return NULL;
}

bool ffmpeg_end_rendering(FFMPEG *ffmpeg, bool cancel)
{
(void)ffmpeg;
(void) cancel;
return false;
}

bool ffmpeg_send_frame_flipped(FFMPEG *ffmpeg, void *data, size_t width, size_t height)
{
(void)ffmpeg;
(void)data;
(void)width;
(void)height;
return false;
}

bool ffmpeg_send_sound_samples(FFMPEG *ffmpeg, void *data, size_t size)
{
(void)ffmpeg;
(void)data;
(void)size;
return false;
}
33 changes: 32 additions & 1 deletion panim/panim.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
#include <raylib.h>
#include <raymath.h>

#include <dlfcn.h>
#ifndef _WIN32
//#include <dlfcn.h>
#endif

#define NOB_IMPLEMENTATION
#include "nob.h"
Expand Down Expand Up @@ -46,6 +48,34 @@ static float delta_time_multiplier_popup = 0.0f;
LIST_OF_PLUGS
#undef PLUG

#ifdef _WIN32
static bool reload_libplug(const char *libplug_path)
{
if (libplug != NULL) {
FreeLibrary (libplug);
}


nob_copy_file(libplug_path, "tmpplug.dll");
libplug = LoadLibraryA("tmpplug.dll");
if (libplug == NULL) {
fprintf(stderr, "ERROR: %d\n", GetLastError ());
return false;
}

#define PLUG(name, ret, ...) \
name = ( ret(*)(__VA_ARGS__) )GetProcAddress (libplug, #name); \
if (name == NULL) { \
fprintf(stderr, "ERROR: %d\n", GetLastError ()); \
return false; \
}
LIST_OF_PLUGS

#undef PLUG

return true;
}
#else
static bool reload_libplug(const char *libplug_path)
{
if (libplug != NULL) {
Expand All @@ -69,6 +99,7 @@ static bool reload_libplug(const char *libplug_path)

return true;
}
#endif

static void finish_ffmpeg_video_rendering(bool cancel)
{
Expand Down
Loading