push
This commit is contained in:
parent
36ad203575
commit
87804afc7d
4
.gitmodules
vendored
4
.gitmodules
vendored
|
@ -1,3 +1,7 @@
|
|||
[submodule "rlImGui"]
|
||||
path = 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
|
||||
|
||||
CC=g++
|
||||
CFLAGS=-O3 -Wall -Wextra -Iimgui -IrlImGui
|
||||
CFLAGS=-O3 -Wall -Wextra -Iimgui -IrlImGui -Iuuid -std=c++11
|
||||
LDFLAGS=-lraylib -lm
|
||||
|
||||
CFILES=$(shell find -L * -type f -name '*.cpp')
|
||||
CFILES=$(shell find src -type f -name '*.cpp')
|
||||
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
|
||||
$(CC) $(OBJ) $(LDFLAGS) -o $@
|
||||
COMPILE=$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
%.o: %.cpp
|
||||
$(CC) $(CFLAGS) -c $< -o $@
|
||||
$(BINARY): $(OBJ) $(DEPOBJ) Makefile
|
||||
$(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)
|
||||
./$(BINARY)
|
||||
|
||||
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]
|
||||
Pos=0,19
|
||||
Size=1362,710
|
||||
Collapsed=0
|
||||
|
||||
[Window][Debug##Default]
|
||||
Pos=60,60
|
||||
Size=400,400
|
||||
Collapsed=0
|
||||
|
||||
[Window][Game Objects]
|
||||
Pos=0,19
|
||||
Size=231,710
|
||||
Size=277,710
|
||||
Collapsed=0
|
||||
DockId=0x00000003,0
|
||||
|
||||
[Window][Properties]
|
||||
Pos=781,20
|
||||
Size=281,528
|
||||
Pos=1099,19
|
||||
Size=263,510
|
||||
Collapsed=0
|
||||
DockId=0x00000005,0
|
||||
|
||||
[Window][Viewport]
|
||||
Pos=233,19
|
||||
Size=846,710
|
||||
Pos=279,19
|
||||
Size=818,710
|
||||
Collapsed=0
|
||||
DockId=0x00000007,0
|
||||
|
||||
[Window][Dear ImGui Demo]
|
||||
Pos=233,476
|
||||
Size=846,253
|
||||
Pos=279,497
|
||||
Size=818,232
|
||||
Collapsed=0
|
||||
DockId=0x00000008,0
|
||||
|
||||
[Window][Dear ImGui Metrics/Debugger]
|
||||
Pos=233,476
|
||||
Size=846,253
|
||||
Collapsed=0
|
||||
|
||||
[Window][About]
|
||||
Pos=1081,545
|
||||
Size=281,184
|
||||
Collapsed=0
|
||||
|
||||
[Window][Debug]
|
||||
Pos=781,549
|
||||
Size=281,180
|
||||
Pos=1099,531
|
||||
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 <imgui.h>
|
||||
#include <rlImGui.h>
|
||||
#include <rlgl.h>
|
||||
#include "pch.h"
|
||||
|
||||
#include "viewport.h"
|
||||
|
||||
typedef struct game_object_t {
|
||||
char name[128];
|
||||
} game_object;
|
||||
struct game_object {
|
||||
std::string name;
|
||||
std::string uuid;
|
||||
};
|
||||
|
||||
const char* gl_versions[7] = {
|
||||
"UNKNOWN",
|
||||
|
@ -24,11 +20,11 @@ Camera camera;
|
|||
int main() {
|
||||
SetConfigFlags(FLAG_WINDOW_RESIZABLE);
|
||||
InitWindow(800, 600, "gear");
|
||||
//InitViewport();
|
||||
InitViewport();
|
||||
|
||||
rlImGuiSetup(true);
|
||||
/*ImGuiIO *ioptr = igGetIO();
|
||||
ioptr->ConfigFlags |= ImGuiConfigFlags_DockingEnable;*/
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
|
||||
|
||||
camera = (Camera){};
|
||||
camera.position = (Vector3) { 10.0f, 10.0f, 10.0f };
|
||||
|
@ -104,23 +100,25 @@ int main() {
|
|||
bool show_demo = false;
|
||||
bool show_debug = true;
|
||||
|
||||
/*sl_vec(game_object*) game_objects = { 0 };
|
||||
std::vector<game_object*> game_objects;
|
||||
for(int i = 0; i < 10000; i++) {
|
||||
game_object* obj = calloc(sizeof(game_object), 1);
|
||||
snprintf(obj->name, 128, "bob %d", i);
|
||||
sl_vec_push(game_objects, obj);
|
||||
}*/
|
||||
game_object* obj = new game_object;
|
||||
obj->name = std::string("object ") + std::to_string(i);
|
||||
obj->uuid = UUID::generate_uuid();
|
||||
|
||||
game_objects.push_back(obj);
|
||||
}
|
||||
|
||||
game_object* selected = NULL;
|
||||
|
||||
while(!WindowShouldClose()) {
|
||||
//UpdateViewport();
|
||||
UpdateViewport();
|
||||
|
||||
BeginDrawing();
|
||||
{
|
||||
ClearBackground(BLACK);
|
||||
|
||||
/*BeginViewport();
|
||||
BeginViewport();
|
||||
{
|
||||
ClearBackground(BLACK);
|
||||
BeginMode3D(camera);
|
||||
|
@ -133,62 +131,65 @@ int main() {
|
|||
DrawFPS(10, 10);
|
||||
//DrawText(TextFormat(
|
||||
|
||||
int y = 50;
|
||||
/*int y = 50;
|
||||
for(sl_vec_it(obj, game_objects)) {
|
||||
DrawText(obj->name, 10, y, 20, WHITE);
|
||||
y += 20;
|
||||
}*/
|
||||
}
|
||||
}
|
||||
EndViewport();*/
|
||||
EndViewport();
|
||||
|
||||
rlImGuiBegin();
|
||||
{
|
||||
if(ImGui::BeginMainMenuBar()) {
|
||||
if(ImGui::BeginMenu("File", true)) {
|
||||
if(ImGui::MenuItem("Quit", "ESC", false, true)) {
|
||||
if(ImGui::BeginMenu("File")) {
|
||||
if(ImGui::MenuItem("Quit", "ESC")) {
|
||||
CloseWindow();
|
||||
}
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
|
||||
if(ImGui::BeginMenu("Debug", true)) {
|
||||
if(ImGui::BeginMenu("Debug")) {
|
||||
ImGui::Checkbox("Show demo window", &show_demo);
|
||||
ImGui::Checkbox("Show debug info", &show_debug);
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
|
||||
ImGui::EndMainMenuBar();
|
||||
}
|
||||
|
||||
//ImGui::DockSpaceOverViewport(NULL, 0, NULL);
|
||||
ImGui::DockSpaceOverViewport();
|
||||
|
||||
if(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)) {
|
||||
char* name = (*obj)->name;
|
||||
if(strcmp(name, "") == 0) name = " ";
|
||||
if(igSelectable_Bool(name, selected == *obj, 0, (ImVec2){0, 0}))
|
||||
selected = *obj;
|
||||
}*/
|
||||
for(const auto& obj : game_objects) {
|
||||
ImGui::PushID(obj->uuid.c_str());
|
||||
if(ImGui::Selectable(obj->name.c_str(), selected == obj))
|
||||
selected = obj;
|
||||
ImGui::PopID();
|
||||
}
|
||||
}
|
||||
ImGui::End();
|
||||
|
||||
ImGui::Begin("Properties", NULL, 0);
|
||||
ImGui::Begin("Properties");
|
||||
{
|
||||
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();
|
||||
|
||||
if(show_debug) {
|
||||
ImGui::Begin("Debug", &show_debug, 0);
|
||||
ImGui::Begin("Debug", &show_debug);
|
||||
{
|
||||
ImGui::Text("raylib %s", RAYLIB_VERSION);
|
||||
ImGui::Text("imgui %s", IMGUI_VERSION);
|
||||
ImGui::Text("OpenGL %s", gl_versions[rlGetVersion()]);
|
||||
ImGui::Text("FPS: %d", GetFPS());
|
||||
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 <raylib.h>
|
||||
#include <rlcimgui.h>
|
||||
#include <imgui_impl_raylib.h>
|
||||
#include <stddef.h>
|
||||
#include <imgui.h>
|
||||
#include <rlImGui.h>
|
||||
|
||||
extern Camera camera;
|
||||
RenderTexture viewport;
|
||||
|
@ -30,11 +29,11 @@ void EndViewport() {
|
|||
}
|
||||
|
||||
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(!IsCursorHidden())
|
||||
DisableCursor();
|
||||
|
@ -48,17 +47,16 @@ void RenderViewport() {
|
|||
EnableCursor();
|
||||
}
|
||||
|
||||
ImVec2 area;
|
||||
igGetContentRegionAvail(&area);
|
||||
ImVec2 area = ImGui::GetContentRegionAvail();
|
||||
|
||||
if(viewport.texture.width != area.x || viewport.texture.height != area.y) {
|
||||
new_viewport = LoadRenderTexture(area.x, area.y);
|
||||
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