Skip to content

Commit efaa7b3

Browse files
committed
Merge branch 'main' of https://github.com/geode-sdk/DevTools into main
2 parents 268ac42 + 752a6cc commit efaa7b3

File tree

13 files changed

+224
-45
lines changed

13 files changed

+224
-45
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ jobs:
1515
- name: Windows
1616
os: windows-latest
1717

18-
#- name: macOS
19-
# os: macos-latest
18+
- name: macOS
19+
os: macos-latest
2020

2121
- name: Android32
2222
os: ubuntu-latest
@@ -35,7 +35,6 @@ jobs:
3535
- name: Build the mod
3636
uses: geode-sdk/build-geode-mod@main
3737
with:
38-
sdk: nightly
3938
combine: true
4039
target: ${{ matrix.config.target }}
4140

CMakeLists.txt

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ file(GLOB_RECURSE SOURCES
88
src/*.cpp
99
)
1010

11-
add_library(${PROJECT_NAME} SHARED ${SOURCES} src/platform/Mac.mm)
11+
add_library(${PROJECT_NAME} SHARED ${SOURCES} src/platform/Mac.mm src/platform/retina.mm)
1212

1313
set_source_files_properties(src/platform/Mac.mm PROPERTIES SKIP_PRECOMPILE_HEADERS ON)
14+
set_source_files_properties(src/platform/retina.mm PROPERTIES SKIP_PRECOMPILE_HEADERS ON)
1415

1516
if (NOT DEFINED ENV{GEODE_SDK})
1617
message(FATAL_ERROR "Unable to find Geode SDK! Please define GEODE_SDK environment variable to point to Geode")
@@ -33,14 +34,6 @@ target_sources(${PROJECT_NAME} PRIVATE
3334
${imgui_SOURCE_DIR}/misc/cpp/imgui_stdlib.cpp
3435
)
3536

36-
if(WIN32)
37-
target_link_libraries(${PROJECT_NAME} opengl32)
38-
elseif(APPLE)
39-
target_link_libraries(${PROJECT_NAME} "-framework OpenGL")
40-
elseif(ANDROID)
41-
target_link_libraries(${PROJECT_NAME} GLESv2)
42-
endif()
43-
4437
# i still dont like this (alk)
4538
target_compile_definitions(geode-sdk INTERFACE GEODE_EXPOSE_SECRET_INTERNALS_IN_HEADERS_DO_NOT_DEFINE_PLEASE)
4639

cmake/CPM.cmake

Lines changed: 0 additions & 21 deletions
This file was deleted.

mod.json

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
{
2-
"geode": "v2.0.0",
3-
"version": "v1.5.0",
4-
"gd": "*",
2+
"geode": "v2.0.0-beta.23",
3+
"version": "v1.6.0",
4+
"gd": {
5+
"win": "*",
6+
"android": "*",
7+
"mac": "2.200"
8+
},
59
"id": "geode.devtools",
610
"name": "DevTools",
711
"developer": "Geode Team",
@@ -10,5 +14,13 @@
1014
"issues": {
1115
"url": "https://github.com/geode-sdk/DevTools/issues",
1216
"info": "If you encounter an issue using DevTools, please report it to the GitHub issues page."
17+
},
18+
"settings": {
19+
"should-use-gd-window": {
20+
"type": "bool",
21+
"name": "Use GD window",
22+
"description": "Determines if the DevTools should use a custom GD window or not. Required to disable for some exotic configurations (MacOS Wine).",
23+
"default": true
24+
}
1325
}
1426
}

src/DevTools.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,18 @@ void DevTools::drawPage(const char* name, void(DevTools::*pageFun)()) {
5151
ImGui::End();
5252
}
5353

54+
#ifndef GEODE_IS_MACOS
55+
56+
float DevTools::retinaFactor() {
57+
return 1.f;
58+
}
59+
60+
#endif
61+
5462
void DevTools::drawPages() {
5563
const auto size = CCDirector::sharedDirector()->getOpenGLView()->getFrameSize();
56-
57-
if (!Mod::get()->setSavedValue("layout-loaded", true) || m_shouldRelayout) {
64+
65+
if ((!Mod::get()->setSavedValue("layout-loaded", true) || m_shouldRelayout)) {
5866
m_shouldRelayout = false;
5967

6068
auto id = m_dockspaceID;
@@ -137,7 +145,7 @@ void DevTools::draw(GLRenderCtx* ctx) {
137145
if (m_selectedNode) {
138146
this->highlightNode(m_selectedNode, HighlightMode::Selected);
139147
}
140-
this->drawGD(ctx);
148+
if (this->shouldUseGDWindow()) this->drawGD(ctx);
141149
ImGui::PopFont();
142150
}
143151
}
@@ -209,3 +217,7 @@ void DevTools::toggle() {
209217
void DevTools::sceneChanged() {
210218
m_selectedNode = nullptr;
211219
}
220+
221+
bool DevTools::shouldUseGDWindow() const {
222+
return Mod::get()->getSettingValue<bool>("should-use-gd-window");
223+
}

src/DevTools.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,15 @@ class DevTools {
6666

6767
void newFrame();
6868
void renderDrawData(ImDrawData*);
69+
void renderDrawDataFallback(ImDrawData*);
70+
71+
bool hasExtension(const std::string& ext) const;
6972

7073
public:
7174
static DevTools* get();
7275

76+
bool shouldUseGDWindow() const;
77+
7378
bool shouldPopGame() const;
7479
bool pausedGame() const;
7580
bool isSetup() const;
@@ -80,6 +85,7 @@ class DevTools {
8085
void highlightNode(CCNode* node, HighlightMode mode);
8186

8287
void sceneChanged();
88+
static float retinaFactor();
8389

8490
void render(GLRenderCtx* ctx);
8591

src/ImGui.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <imgui.h>
44
#include <iostream>
55
#include <cocos2d.h>
6+
#include "DevTools.hpp"
67

78
using namespace cocos2d;
89

src/backend.cpp

Lines changed: 89 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ void DevTools::newFrame() {
3939

4040
auto* director = CCDirector::sharedDirector();
4141
const auto winSize = director->getWinSize();
42-
const auto frameSize = director->getOpenGLView()->getFrameSize();
42+
const auto frameSize = director->getOpenGLView()->getFrameSize() * DevTools::retinaFactor();
4343

4444
// glfw new frame
4545
io.DisplaySize = ImVec2(frameSize.width, frameSize.height);
@@ -76,7 +76,93 @@ void DevTools::render(GLRenderCtx* ctx) {
7676
this->renderDrawData(ImGui::GetDrawData());
7777
}
7878

79+
bool DevTools::hasExtension(const std::string& ext) const {
80+
auto exts = reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS));
81+
if (exts == nullptr) {
82+
return false;
83+
}
84+
85+
std::string extsStr(exts);
86+
log::debug("{}", extsStr);
87+
return extsStr.find(ext) != std::string::npos;
88+
}
89+
90+
namespace {
91+
static void drawTriangle(const std::array<CCPoint, 3>& poli, const std::array<ccColor4F, 3>& colors, const std::array<CCPoint, 3>& uvs) {
92+
auto* shader = CCShaderCache::sharedShaderCache()->programForKey(kCCShader_PositionTextureColor);
93+
shader->use();
94+
shader->setUniformsForBuiltins();
95+
96+
ccGLEnableVertexAttribs(kCCVertexAttribFlag_PosColorTex);
97+
98+
static_assert(sizeof(CCPoint) == sizeof(ccVertex2F), "so the cocos devs were right then");
99+
100+
glVertexAttribPointer(kCCVertexAttrib_Position, 2, GL_FLOAT, GL_FALSE, 0, poli.data());
101+
glVertexAttribPointer(kCCVertexAttrib_Color, 4, GL_FLOAT, GL_FALSE, 0, colors.data());
102+
glVertexAttribPointer(kCCVertexAttrib_TexCoords, 2, GL_FLOAT, GL_FALSE, 0, uvs.data());
103+
104+
glDrawArrays(GL_TRIANGLE_FAN, 0, 3);
105+
}
106+
}
107+
108+
void DevTools::renderDrawDataFallback(ImDrawData* draw_data) {
109+
glEnable(GL_SCISSOR_TEST);
110+
111+
const auto clip_scale = draw_data->FramebufferScale;
112+
113+
for (int i = 0; i < draw_data->CmdListsCount; ++i) {
114+
auto* list = draw_data->CmdLists[i];
115+
auto* idxBuffer = list->IdxBuffer.Data;
116+
auto* vtxBuffer = list->VtxBuffer.Data;
117+
for (auto& cmd : list->CmdBuffer) {
118+
ccGLBindTexture2D(static_cast<GLuint>(reinterpret_cast<intptr_t>(cmd.GetTexID())));
119+
120+
const auto rect = cmd.ClipRect;
121+
const auto orig = toCocos(ImVec2(rect.x, rect.y));
122+
const auto end = toCocos(ImVec2(rect.z, rect.w));
123+
if (end.x <= orig.x || end.y >= orig.y)
124+
continue;
125+
CCDirector::sharedDirector()->getOpenGLView()->setScissorInPoints(orig.x, end.y, end.x - orig.x, orig.y - end.y);
126+
127+
for (unsigned int i = 0; i < cmd.ElemCount; i += 3) {
128+
const auto a = vtxBuffer[idxBuffer[cmd.IdxOffset + i + 0]];
129+
const auto b = vtxBuffer[idxBuffer[cmd.IdxOffset + i + 1]];
130+
const auto c = vtxBuffer[idxBuffer[cmd.IdxOffset + i + 2]];
131+
std::array<CCPoint, 3> points = {
132+
toCocos(a.pos),
133+
toCocos(b.pos),
134+
toCocos(c.pos),
135+
};
136+
static constexpr auto ccc4FromImColor = [](const ImColor color) {
137+
// beautiful
138+
return ccc4f(color.Value.x, color.Value.y, color.Value.z, color.Value.w);
139+
};
140+
std::array<ccColor4F, 3> colors = {
141+
ccc4FromImColor(a.col),
142+
ccc4FromImColor(b.col),
143+
ccc4FromImColor(c.col),
144+
};
145+
146+
std::array<CCPoint, 3> uvs = {
147+
ccp(a.uv.x, a.uv.y),
148+
ccp(b.uv.x, b.uv.y),
149+
ccp(c.uv.x, c.uv.y),
150+
};
151+
152+
drawTriangle(points, colors, uvs);
153+
}
154+
}
155+
}
156+
157+
glDisable(GL_SCISSOR_TEST);
158+
}
159+
79160
void DevTools::renderDrawData(ImDrawData* draw_data) {
161+
static bool hasVaos = this->hasExtension("GL_ARB_vertex_array_object");
162+
if (!hasVaos) {
163+
return this->renderDrawDataFallback(draw_data);
164+
}
165+
80166
glEnable(GL_SCISSOR_TEST);
81167

82168
GLuint vao = 0;
@@ -173,7 +259,7 @@ class $modify(CCTouchDispatcher) {
173259
if (io.WantCaptureMouse) {
174260
bool didGDSwallow = false;
175261

176-
if (shouldPassEventsToGDButTransformed()) {
262+
if (DevTools::get()->shouldUseGDWindow() && shouldPassEventsToGDButTransformed()) {
177263
auto win = ImGui::GetMainViewport()->Size;
178264
const auto gdRect = getGDWindowRect();
179265
if (gdRect.Contains(pos) && !DevTools::get()->pausedGame()) {
@@ -208,7 +294,7 @@ class $modify(CCTouchDispatcher) {
208294
if (type != CCTOUCHMOVED) {
209295
io.AddMouseButtonEvent(0, false);
210296
}
211-
if (!DevTools::get()->shouldPopGame()) {
297+
if (!DevTools::get()->shouldUseGDWindow() || !DevTools::get()->shouldPopGame()) {
212298
CCTouchDispatcher::touches(touches, event, type);
213299
}
214300
}

src/main.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ class $modify(AchievementNotifier) {
5050

5151
class $modify(CCDirector) {
5252
void drawScene() {
53+
if (!DevTools::get()->shouldUseGDWindow()) {
54+
return CCDirector::drawScene();
55+
}
56+
5357
DevTools::get()->setup();
5458

5559
static GLRenderCtx* gdTexture = nullptr;
@@ -72,7 +76,7 @@ class $modify(CCDirector) {
7276
shouldUpdateGDRenderBuffer() = false;
7377
}
7478

75-
auto winSize = this->getOpenGLView()->getViewPortRect();
79+
auto winSize = this->getOpenGLView()->getViewPortRect() * DevTools::retinaFactor();
7680
if (!gdTexture) {
7781
gdTexture = new GLRenderCtx({ winSize.size.width, winSize.size.height });
7882
}
@@ -103,7 +107,7 @@ class $modify(CCEGLView) {
103107
// but before the buffers have been swapped, which is not possible with just a
104108
// CCDirector::drawScene hook.
105109
void swapBuffers() {
106-
if (!DevTools::get()->shouldPopGame()) {
110+
if (!DevTools::get()->shouldUseGDWindow() || !DevTools::get()->shouldPopGame()) {
107111
DevTools::get()->setup();
108112
DevTools::get()->render(nullptr);
109113
}

src/pages/Advanced.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ namespace {
7474
ModMetadata DevTools::inputMetadata(void* treePtr, ModMetadata metadata) {
7575
metadata.setVersion(inputVersion(metadata.getVersion()));
7676
metadata.setName(inputText("name", metadata.getName()));
77-
metadata.setDeveloper(inputText("developer", metadata.getDeveloper()));
77+
metadata.setDeveloper(inputText("developer", metadata.getDevelopers()[0]));
7878
metadata.setDescription(inputTextMultiline("description", metadata.getDescription()));
7979
metadata.setDetails(inputTextMultiline("details", metadata.getDetails()));
8080
metadata.setChangelog(inputTextMultiline("changelog", metadata.getChangelog()));

0 commit comments

Comments
 (0)