push
This commit is contained in:
parent
36ad203575
commit
87804afc7d
4
.gitmodules
vendored
4
.gitmodules
vendored
|
@ -1,3 +1,7 @@
|
||||||
[submodule "rlImGui"]
|
[submodule "rlImGui"]
|
||||||
path = rlImGui
|
path = rlImGui
|
||||||
url = https://github.com/raylib-extras/rlImGui
|
url = https://github.com/raylib-extras/rlImGui
|
||||||
|
[submodule "imgui"]
|
||||||
|
path = imgui
|
||||||
|
url = https://github.com/ocornut/imgui
|
||||||
|
branch = docking
|
||||||
|
|
30
Makefile
30
Makefile
|
@ -1,21 +1,37 @@
|
||||||
BINARY=gear
|
BINARY=gear
|
||||||
|
|
||||||
CC=g++
|
CC=g++
|
||||||
CFLAGS=-O3 -Wall -Wextra -Iimgui -IrlImGui
|
CFLAGS=-O3 -Wall -Wextra -Iimgui -IrlImGui -Iuuid -std=c++11
|
||||||
LDFLAGS=-lraylib -lm
|
LDFLAGS=-lraylib -lm
|
||||||
|
|
||||||
CFILES=$(shell find -L * -type f -name '*.cpp')
|
CFILES=$(shell find src -type f -name '*.cpp')
|
||||||
OBJ=$(CFILES:.cpp=.o)
|
OBJ=$(CFILES:.cpp=.o)
|
||||||
|
DEPFILES=$(shell echo imgui/*.cpp) \
|
||||||
|
imgui/misc/cpp/imgui_stdlib.cpp \
|
||||||
|
$(shell echo rlImGui/*.cpp) \
|
||||||
|
uuid/uuid.cpp
|
||||||
|
DEPOBJ=$(DEPFILES:.cpp=.o)
|
||||||
|
|
||||||
$(BINARY): $(OBJ) Makefile
|
COMPILE=$(CC) $(CFLAGS) -c $< -o $@
|
||||||
$(CC) $(OBJ) $(LDFLAGS) -o $@
|
|
||||||
|
|
||||||
%.o: %.cpp
|
$(BINARY): $(OBJ) $(DEPOBJ) Makefile
|
||||||
$(CC) $(CFLAGS) -c $< -o $@
|
$(CC) $(OBJ) $(DEPOBJ) $(LDFLAGS) -o $@
|
||||||
|
|
||||||
|
src/%.o: src/%.cpp
|
||||||
|
$(COMPILE)
|
||||||
|
|
||||||
|
imgui/%.o: imgui/%.cpp
|
||||||
|
$(COMPILE)
|
||||||
|
|
||||||
|
rlImGui/%.o: rlImGui/%.cpp
|
||||||
|
$(COMPILE)
|
||||||
|
|
||||||
|
uuid/%.o: uuid/%.cpp
|
||||||
|
$(COMPILE)
|
||||||
|
|
||||||
run: $(BINARY)
|
run: $(BINARY)
|
||||||
./$(BINARY)
|
./$(BINARY)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf $(OBJ) $(BINARY)
|
rm -rf $(OBJ) $(DEPS) $(BINARY)
|
||||||
|
|
||||||
|
|
1
imgui
Submodule
1
imgui
Submodule
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit b555984a94b1c5a5f2f192d1513547c4b112c976
|
48
imgui.ini
48
imgui.ini
|
@ -1,36 +1,66 @@
|
||||||
[Window][DockSpaceViewport_11111111]
|
[Window][DockSpaceViewport_11111111]
|
||||||
Pos=0,19
|
Pos=0,19
|
||||||
Size=1362,710
|
Size=1362,710
|
||||||
|
Collapsed=0
|
||||||
|
|
||||||
[Window][Debug##Default]
|
[Window][Debug##Default]
|
||||||
Pos=60,60
|
Pos=60,60
|
||||||
Size=400,400
|
Size=400,400
|
||||||
|
Collapsed=0
|
||||||
|
|
||||||
[Window][Game Objects]
|
[Window][Game Objects]
|
||||||
Pos=0,19
|
Pos=0,19
|
||||||
Size=231,710
|
Size=277,710
|
||||||
|
Collapsed=0
|
||||||
|
DockId=0x00000003,0
|
||||||
|
|
||||||
[Window][Properties]
|
[Window][Properties]
|
||||||
Pos=781,20
|
Pos=1099,19
|
||||||
Size=281,528
|
Size=263,510
|
||||||
|
Collapsed=0
|
||||||
|
DockId=0x00000005,0
|
||||||
|
|
||||||
[Window][Viewport]
|
[Window][Viewport]
|
||||||
Pos=233,19
|
Pos=279,19
|
||||||
Size=846,710
|
Size=818,710
|
||||||
|
Collapsed=0
|
||||||
|
DockId=0x00000007,0
|
||||||
|
|
||||||
[Window][Dear ImGui Demo]
|
[Window][Dear ImGui Demo]
|
||||||
Pos=233,476
|
Pos=279,497
|
||||||
Size=846,253
|
Size=818,232
|
||||||
|
Collapsed=0
|
||||||
|
DockId=0x00000008,0
|
||||||
|
|
||||||
[Window][Dear ImGui Metrics/Debugger]
|
[Window][Dear ImGui Metrics/Debugger]
|
||||||
Pos=233,476
|
Pos=233,476
|
||||||
Size=846,253
|
Size=846,253
|
||||||
|
Collapsed=0
|
||||||
|
|
||||||
[Window][About]
|
[Window][About]
|
||||||
Pos=1081,545
|
Pos=1081,545
|
||||||
Size=281,184
|
Size=281,184
|
||||||
|
Collapsed=0
|
||||||
|
|
||||||
[Window][Debug]
|
[Window][Debug]
|
||||||
Pos=781,549
|
Pos=1099,531
|
||||||
Size=281,180
|
Size=263,198
|
||||||
|
Collapsed=0
|
||||||
|
DockId=0x00000006,0
|
||||||
|
|
||||||
|
[Window][Dear ImGui Style Editor]
|
||||||
|
Pos=60,60
|
||||||
|
Size=353,704
|
||||||
|
Collapsed=0
|
||||||
|
|
||||||
|
[Docking][Data]
|
||||||
|
DockSpace ID=0x8B93E3BD Window=0xA787BDB4 Pos=0,19 Size=1362,710 Split=X Selected=0x13926F0B
|
||||||
|
DockNode ID=0x00000003 Parent=0x8B93E3BD SizeRef=277,710 Selected=0x09CA5163
|
||||||
|
DockNode ID=0x00000004 Parent=0x8B93E3BD SizeRef=1083,710 Split=X
|
||||||
|
DockNode ID=0x00000001 Parent=0x00000004 SizeRef=818,710 Split=Y Selected=0x13926F0B
|
||||||
|
DockNode ID=0x00000007 Parent=0x00000001 SizeRef=818,476 CentralNode=1 Selected=0x13926F0B
|
||||||
|
DockNode ID=0x00000008 Parent=0x00000001 SizeRef=818,232 Selected=0xE87781F4
|
||||||
|
DockNode ID=0x00000002 Parent=0x00000004 SizeRef=263,710 Split=Y Selected=0x199AB496
|
||||||
|
DockNode ID=0x00000005 Parent=0x00000002 SizeRef=263,510 Selected=0x199AB496
|
||||||
|
DockNode ID=0x00000006 Parent=0x00000002 SizeRef=263,198 Selected=0x392A5ADD
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,9 @@
|
||||||
#include <raylib.h>
|
#include "pch.h"
|
||||||
#include <imgui.h>
|
|
||||||
#include <rlImGui.h>
|
|
||||||
#include <rlgl.h>
|
|
||||||
|
|
||||||
#include "viewport.h"
|
struct game_object {
|
||||||
|
std::string name;
|
||||||
typedef struct game_object_t {
|
std::string uuid;
|
||||||
char name[128];
|
};
|
||||||
} game_object;
|
|
||||||
|
|
||||||
const char* gl_versions[7] = {
|
const char* gl_versions[7] = {
|
||||||
"UNKNOWN",
|
"UNKNOWN",
|
||||||
|
@ -24,11 +20,11 @@ Camera camera;
|
||||||
int main() {
|
int main() {
|
||||||
SetConfigFlags(FLAG_WINDOW_RESIZABLE);
|
SetConfigFlags(FLAG_WINDOW_RESIZABLE);
|
||||||
InitWindow(800, 600, "gear");
|
InitWindow(800, 600, "gear");
|
||||||
//InitViewport();
|
InitViewport();
|
||||||
|
|
||||||
rlImGuiSetup(true);
|
rlImGuiSetup(true);
|
||||||
/*ImGuiIO *ioptr = igGetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
ioptr->ConfigFlags |= ImGuiConfigFlags_DockingEnable;*/
|
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
|
||||||
|
|
||||||
camera = (Camera){};
|
camera = (Camera){};
|
||||||
camera.position = (Vector3) { 10.0f, 10.0f, 10.0f };
|
camera.position = (Vector3) { 10.0f, 10.0f, 10.0f };
|
||||||
|
@ -104,23 +100,25 @@ int main() {
|
||||||
bool show_demo = false;
|
bool show_demo = false;
|
||||||
bool show_debug = true;
|
bool show_debug = true;
|
||||||
|
|
||||||
/*sl_vec(game_object*) game_objects = { 0 };
|
std::vector<game_object*> game_objects;
|
||||||
for(int i = 0; i < 10000; i++) {
|
for(int i = 0; i < 10000; i++) {
|
||||||
game_object* obj = calloc(sizeof(game_object), 1);
|
game_object* obj = new game_object;
|
||||||
snprintf(obj->name, 128, "bob %d", i);
|
obj->name = std::string("object ") + std::to_string(i);
|
||||||
sl_vec_push(game_objects, obj);
|
obj->uuid = UUID::generate_uuid();
|
||||||
}*/
|
|
||||||
|
game_objects.push_back(obj);
|
||||||
|
}
|
||||||
|
|
||||||
game_object* selected = NULL;
|
game_object* selected = NULL;
|
||||||
|
|
||||||
while(!WindowShouldClose()) {
|
while(!WindowShouldClose()) {
|
||||||
//UpdateViewport();
|
UpdateViewport();
|
||||||
|
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
{
|
{
|
||||||
ClearBackground(BLACK);
|
ClearBackground(BLACK);
|
||||||
|
|
||||||
/*BeginViewport();
|
BeginViewport();
|
||||||
{
|
{
|
||||||
ClearBackground(BLACK);
|
ClearBackground(BLACK);
|
||||||
BeginMode3D(camera);
|
BeginMode3D(camera);
|
||||||
|
@ -133,62 +131,65 @@ int main() {
|
||||||
DrawFPS(10, 10);
|
DrawFPS(10, 10);
|
||||||
//DrawText(TextFormat(
|
//DrawText(TextFormat(
|
||||||
|
|
||||||
int y = 50;
|
/*int y = 50;
|
||||||
for(sl_vec_it(obj, game_objects)) {
|
for(sl_vec_it(obj, game_objects)) {
|
||||||
DrawText(obj->name, 10, y, 20, WHITE);
|
DrawText(obj->name, 10, y, 20, WHITE);
|
||||||
y += 20;
|
y += 20;
|
||||||
|
}*/
|
||||||
}
|
}
|
||||||
}
|
EndViewport();
|
||||||
EndViewport();*/
|
|
||||||
|
|
||||||
rlImGuiBegin();
|
rlImGuiBegin();
|
||||||
{
|
{
|
||||||
if(ImGui::BeginMainMenuBar()) {
|
if(ImGui::BeginMainMenuBar()) {
|
||||||
if(ImGui::BeginMenu("File", true)) {
|
if(ImGui::BeginMenu("File")) {
|
||||||
if(ImGui::MenuItem("Quit", "ESC", false, true)) {
|
if(ImGui::MenuItem("Quit", "ESC")) {
|
||||||
CloseWindow();
|
CloseWindow();
|
||||||
}
|
}
|
||||||
ImGui::EndMenu();
|
ImGui::EndMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ImGui::BeginMenu("Debug", true)) {
|
if(ImGui::BeginMenu("Debug")) {
|
||||||
ImGui::Checkbox("Show demo window", &show_demo);
|
ImGui::Checkbox("Show demo window", &show_demo);
|
||||||
|
ImGui::Checkbox("Show debug info", &show_debug);
|
||||||
ImGui::EndMenu();
|
ImGui::EndMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::EndMainMenuBar();
|
ImGui::EndMainMenuBar();
|
||||||
}
|
}
|
||||||
|
|
||||||
//ImGui::DockSpaceOverViewport(NULL, 0, NULL);
|
ImGui::DockSpaceOverViewport();
|
||||||
|
|
||||||
if(show_demo)
|
if(show_demo)
|
||||||
ImGui::ShowDemoWindow(&show_demo);
|
ImGui::ShowDemoWindow(&show_demo);
|
||||||
|
|
||||||
//RenderViewport();
|
RenderViewport();
|
||||||
|
|
||||||
ImGui::Begin("Game Objects", NULL, 0);
|
ImGui::Begin("Game Objects");
|
||||||
{
|
{
|
||||||
/*for(sl_vec_it(obj, game_objects)) {
|
for(const auto& obj : game_objects) {
|
||||||
char* name = (*obj)->name;
|
ImGui::PushID(obj->uuid.c_str());
|
||||||
if(strcmp(name, "") == 0) name = " ";
|
if(ImGui::Selectable(obj->name.c_str(), selected == obj))
|
||||||
if(igSelectable_Bool(name, selected == *obj, 0, (ImVec2){0, 0}))
|
selected = obj;
|
||||||
selected = *obj;
|
ImGui::PopID();
|
||||||
}*/
|
}
|
||||||
}
|
}
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
|
|
||||||
ImGui::Begin("Properties", NULL, 0);
|
ImGui::Begin("Properties");
|
||||||
{
|
{
|
||||||
if(selected != NULL) {
|
if(selected != NULL) {
|
||||||
ImGui::InputText("##name", selected->name, 128, 0, NULL, NULL);
|
ImGui::InputText("##name", &selected->name);
|
||||||
|
ImGui::Text("UUID: %s", selected->uuid.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
|
|
||||||
if(show_debug) {
|
if(show_debug) {
|
||||||
ImGui::Begin("Debug", &show_debug, 0);
|
ImGui::Begin("Debug", &show_debug);
|
||||||
{
|
{
|
||||||
ImGui::Text("raylib %s", RAYLIB_VERSION);
|
ImGui::Text("raylib %s", RAYLIB_VERSION);
|
||||||
|
ImGui::Text("imgui %s", IMGUI_VERSION);
|
||||||
ImGui::Text("OpenGL %s", gl_versions[rlGetVersion()]);
|
ImGui::Text("OpenGL %s", gl_versions[rlGetVersion()]);
|
||||||
ImGui::Text("FPS: %d", GetFPS());
|
ImGui::Text("FPS: %d", GetFPS());
|
||||||
ImGui::Text("Frame time: %f", GetFrameTime());
|
ImGui::Text("Frame time: %f", GetFrameTime());
|
BIN
src/main.o
Normal file
BIN
src/main.o
Normal file
Binary file not shown.
1
src/pch.cpp
Normal file
1
src/pch.cpp
Normal file
|
@ -0,0 +1 @@
|
||||||
|
#include "pch.h"
|
11
src/pch.h
Normal file
11
src/pch.h
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
#include <raylib.h>
|
||||||
|
#include <imgui.h>
|
||||||
|
#include <misc/cpp/imgui_stdlib.h>
|
||||||
|
#include <rlImGui.h>
|
||||||
|
#include <rlgl.h>
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
#include <iostream>
|
||||||
|
#include <uuid.h>
|
||||||
|
|
||||||
|
#include "viewport.h"
|
|
@ -1,8 +1,7 @@
|
||||||
#include "viewport.h"
|
#include "viewport.h"
|
||||||
#include <raylib.h>
|
#include <raylib.h>
|
||||||
#include <rlcimgui.h>
|
#include <imgui.h>
|
||||||
#include <imgui_impl_raylib.h>
|
#include <rlImGui.h>
|
||||||
#include <stddef.h>
|
|
||||||
|
|
||||||
extern Camera camera;
|
extern Camera camera;
|
||||||
RenderTexture viewport;
|
RenderTexture viewport;
|
||||||
|
@ -30,11 +29,11 @@ void EndViewport() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderViewport() {
|
void RenderViewport() {
|
||||||
igPushStyleVar_Vec2(ImGuiStyleVar_WindowPadding, (ImVec2){0.0f, 0.0f});
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, (ImVec2){0.0f, 0.0f});
|
||||||
|
|
||||||
igBegin("Viewport", NULL, ImGuiWindowFlags_NoScrollbar);
|
ImGui::Begin("Viewport", NULL, ImGuiWindowFlags_NoScrollbar);
|
||||||
{
|
{
|
||||||
if(igIsWindowHovered(0)) {
|
if(ImGui::IsWindowHovered()) {
|
||||||
if(IsMouseButtonDown(MOUSE_BUTTON_RIGHT)) {
|
if(IsMouseButtonDown(MOUSE_BUTTON_RIGHT)) {
|
||||||
if(!IsCursorHidden())
|
if(!IsCursorHidden())
|
||||||
DisableCursor();
|
DisableCursor();
|
||||||
|
@ -48,17 +47,16 @@ void RenderViewport() {
|
||||||
EnableCursor();
|
EnableCursor();
|
||||||
}
|
}
|
||||||
|
|
||||||
ImVec2 area;
|
ImVec2 area = ImGui::GetContentRegionAvail();
|
||||||
igGetContentRegionAvail(&area);
|
|
||||||
|
|
||||||
if(viewport.texture.width != area.x || viewport.texture.height != area.y) {
|
if(viewport.texture.width != area.x || viewport.texture.height != area.y) {
|
||||||
new_viewport = LoadRenderTexture(area.x, area.y);
|
new_viewport = LoadRenderTexture(area.x, area.y);
|
||||||
swap_viewport = true;
|
swap_viewport = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
rligImageRenderTexture(&viewport);
|
rlImGuiImageRenderTexture(&viewport);
|
||||||
}
|
}
|
||||||
igEnd();
|
ImGui::End();
|
||||||
|
|
||||||
igPopStyleVar(1);
|
ImGui::PopStyleVar();
|
||||||
}
|
}
|
BIN
src/viewport.o
Normal file
BIN
src/viewport.o
Normal file
Binary file not shown.
31
uuid/uuid.cpp
Normal file
31
uuid/uuid.cpp
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
#include "uuid.h"
|
||||||
|
#include <random>
|
||||||
|
#include <sstream>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
std::string UUID::generate_uuid() {
|
||||||
|
std::stringstream hexstream;
|
||||||
|
hexstream << UUID::generate_hex(4) << "-" << UUID::generate_hex(2) << "-"
|
||||||
|
<< UUID::generate_hex(2) << "-" << UUID::generate_hex(2) << "-"
|
||||||
|
<< UUID::generate_hex(6);
|
||||||
|
return hexstream.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string UUID::generate_hex(const unsigned int len) {
|
||||||
|
std::stringstream ss;
|
||||||
|
for (auto i = 0; i < len; i++) {
|
||||||
|
const auto rc = random_char();
|
||||||
|
std::stringstream hexstream;
|
||||||
|
hexstream << std::hex << rc;
|
||||||
|
auto hex = hexstream.str();
|
||||||
|
ss << (hex.length() < 2 ? '0' + hex : hex);
|
||||||
|
}
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int UUID::random_char() {
|
||||||
|
std::random_device rd;
|
||||||
|
std::mt19937 gen(rd());
|
||||||
|
std::uniform_int_distribution<> dis(0, 255);
|
||||||
|
return dis(gen);
|
||||||
|
}
|
37
uuid/uuid.h
Normal file
37
uuid/uuid.h
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
// UUID.hpp
|
||||||
|
#ifndef UUID_hpp
|
||||||
|
#define UUID_hpp
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
// Random generation courtesy of https://lowrey.me/guid-generation-in-c-11/
|
||||||
|
|
||||||
|
class UUID {
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Generates a uuid string in the form
|
||||||
|
* b9317db-02a2-4882-9b94-d1e1defe8c56
|
||||||
|
*
|
||||||
|
* @return std::string
|
||||||
|
*/
|
||||||
|
static std::string generate_uuid();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @param len Length in bytes
|
||||||
|
* @return std::string String random hex chars (2x length of the bytes)
|
||||||
|
*/
|
||||||
|
static std::string generate_hex(const unsigned int len);
|
||||||
|
|
||||||
|
private:
|
||||||
|
/**
|
||||||
|
* @brief Generates a safe pseudo-random character
|
||||||
|
*
|
||||||
|
* @return unsigned int
|
||||||
|
*/
|
||||||
|
static unsigned int random_char();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
BIN
uuid/uuid.o
Normal file
BIN
uuid/uuid.o
Normal file
Binary file not shown.
Loading…
Reference in a new issue