Add scripts

This commit is contained in:
KP 2024-08-03 11:16:49 -05:00
parent 428db9a136
commit 2e7ba0b153
7 changed files with 121 additions and 4 deletions

View file

@ -0,0 +1,35 @@
; This is a janky set of routines to make building stairs easier.
; More than anything it's just here to show off our fancy scripting
; capabilities. I suppose if you bound this to some keyboard shortcut
; it'd be a good time saver though :)
(progn
; CONFIG:
(define AXIS X)
(define STAIR_SIZE 0.25)
(define (lerp start end percent)
(+ start (* percent (- end start))))
(define (build-stairs-x sx sy sw sl step height-a height-b)
(do ((i 0 (+1 i)))
((>= i (/ sw step)) (print "done"))
(let* ((points (((+ (* i step) sx) sy)
((+ (* i step) sx) (+ sy sl))
((+ (* i step) sx step) (+ sy sl))
((+ (* i step) sx step) sy)))
(floor-height (lerp height-a height-b (/ i (/ sw step))))
(ceiling-height (+ 4 floor-height)))
(make-sector-from-points floor-height ceiling-height points))))
(define (build-stairs-y sx sy sw sl step height-a height-b)
(do ((i 0 (+1 i)))
((>= i (/ sl step)) (print "done"))
(let* ((points ((sx (+ (* i step) sy))
((- sx sw) (+ (* i step) sy))
((- sx sw) (+ (* i step) sy step))
(sx (+ (* i step) sy step))))
(floor-height (lerp height-a height-b (/ i (/ sl step))))
(ceiling-height (+ 4 floor-height)))
(make-sector-from-points floor-height ceiling-height points))))
(fill-selection
(lambda (x1 y1 x2 y2 nh1 nh2 dir)
(if (= AXIS X)
(build-stairs-x x1 y1 (abs (- x2 x1)) (abs (- y2 y1)) STAIR_SIZE nh1 nh2)
(build-stairs-y x2 y2 (abs (- x2 x1)) (abs (- y2 y1)) STAIR_SIZE nh1 nh2)))))

View file

@ -0,0 +1,59 @@
[11:10:09 AM] Info: Starting...
KP3D version 2
===============================
Copyright (C) kpworld.xyz 2018-2024
Contact me! @kp_cftsz
[11:10:09 AM] Info: Initializing SDL
[11:10:09 AM] Info: Initializing OpenGL
[11:10:09 AM] Info: OpenGL version: 4.6.0 NVIDIA 536.23
[11:10:09 AM] Info: Initializing GLEW
[11:10:09 AM] Info: Initializing SDL_mixer
[11:10:10 AM] Info: Reticulating splines...
[11:10:10 AM] Info: Ready!
[11:10:10 AM] Info: Loading material resource: block.png
[11:10:10 AM] Info: Found normal map texture: materials/block_n.png
[11:10:10 AM] Info: Loading material resource: brick2.jpg
[11:10:10 AM] Info: Found normal map texture: materials/brick2_n.jpg
[11:10:10 AM] Info: Loading material resource: bricks.jpg
[11:10:10 AM] Info: Found normal map texture: materials/bricks_n.jpg
[11:10:10 AM] Info: Loading material resource: FLAT5_7.png
[11:10:10 AM] Info: Found normal map texture: materials/FLAT5_7_n.png
[11:10:10 AM] Info: Loading material resource: floor0.png
[11:10:10 AM] Info: Found normal map texture: materials/floor0_n.png
[11:10:10 AM] Info: Loading material resource: floor1.png
[11:10:10 AM] Info: Found normal map texture: materials/floor1_n.png
[11:10:10 AM] Info: Loading material resource: GRASS2.png
[11:10:10 AM] Info: Found normal map texture: materials/GRASS2_n.png
[11:10:10 AM] Info: Loading material resource: hardwood.jpg
[11:10:10 AM] Info: Found normal map texture: materials/hardwood_n.jpg
[11:10:10 AM] Info: Map init
[11:10:10 AM] Info: Finalized mesh with 49 batches
[11:10:14 AM] Info: Finalized mesh with 54 batches
[11:10:27 AM] Info: [Editor] Filling selection; sector heights 0, -1
[11:10:27 AM] Info: Finalized mesh with 60 batches
[11:10:27 AM] Info: Finalized mesh with 66 batches
[11:10:27 AM] Info: Finalized mesh with 72 batches
[11:10:27 AM] Info: Finalized mesh with 78 batches
[11:10:27 AM] Info: Finalized mesh with 84 batches
[11:10:27 AM] Info: Finalized mesh with 90 batches
[11:10:27 AM] Info: Finalized mesh with 96 batches
[11:10:27 AM] Info: Finalized mesh with 102 batches
[11:10:27 AM] Info: Finalized mesh with 108 batches
[11:10:27 AM] Info: Finalized mesh with 114 batches
[11:10:27 AM] Info: Finalized mesh with 120 batches
[11:10:27 AM] Info: Finalized mesh with 126 batches
[11:10:27 AM] Info: Finalized mesh with 132 batches
[11:10:27 AM] Info: Finalized mesh with 138 batches
[11:10:27 AM] Info: Finalized mesh with 144 batches
[11:10:27 AM] Info: Finalized mesh with 150 batches
[11:10:27 AM] Info: Finalized mesh with 156 batches
[11:10:27 AM] Info: Finalized mesh with 162 batches
[11:10:27 AM] Info: Finalized mesh with 168 batches
[11:10:27 AM] Info: Finalized mesh with 174 batches
[11:10:27 AM] Info: Finalized mesh with 180 batches
[11:10:27 AM] Info: Finalized mesh with 186 batches
[11:10:27 AM] Info: Finalized mesh with 192 batches
[11:10:27 AM] Info: Finalized mesh with 200 batches
[11:10:27 AM] Info: $ : done

View file

@ -3005,7 +3005,11 @@ const TextEditor::LanguageDefinition& TextEditor::LanguageDefinition::Lisp()
langDef.mKeywords.insert(k); langDef.mKeywords.insert(k);
static const char* const identifiers[] = { static const char* const identifiers[] = {
"sin", "cos", "sqrt", "abs", "log", "log10", "floor", "ceil", "atan2", "PI", "E", "car", "cdr", "cons", "list", "list-ref", "print", "exit", "+1", "-1", "null?" "sin", "cos", "sqrt", "abs", "log", "log10", "floor", "ceil", "atan2", "PI", "E", "car", "cdr", "cons", "list", "list-ref", "print", "exit", "+1", "-1", "null?",
// Map editor specific
"make-sector-from-points",
"fill-selection",
"X", "Y"
}; };
for (auto& k : identifiers) for (auto& k : identifiers)
{ {

View file

@ -1,5 +1,7 @@
#include "KP3D_Console.h" #include "KP3D_Console.h"
#include <regex>
#include <imgui.h> #include <imgui.h>
#include "KP3D_Log.h" #include "KP3D_Log.h"
@ -134,8 +136,18 @@ void SendCommand(const std::string& command)
SendKSI("(" + command + ")"); SendKSI("(" + command + ")");
} }
void SendKSI(const std::string& ksi) void SendKSI(std::string ksi)
{ {
// Remove comments (BRAINDEAD WAY OF DOING THIS)
auto lines = str::SplitTokens(ksi, "\n");
for (const auto& line: lines)
if (str::StartsWith(line, ";"))
str::ReplaceAll(ksi, line, "");
// Single line
kp3d::str::ReplaceAll(ksi, "\n", "");
// Now eval
reader.Clear(); reader.Clear();
reader.Tokenize(ksi); reader.Tokenize(ksi);
ksi::Cell c = reader.ReadForm(); ksi::Cell c = reader.ReadForm();

View file

@ -9,7 +9,7 @@ namespace kp3d::console {
void Init(); void Init();
void Render(); void Render();
void SendCommand(const std::string& command); void SendCommand(const std::string& command);
void SendKSI(const std::string& ksi); void SendKSI(std::string ksi);
extern bool open; extern bool open;
extern ksi::Environment environment; extern ksi::Environment environment;

View file

@ -598,6 +598,8 @@ void Environment::Init()
Set("atan2", FAtan2()); Set("atan2", FAtan2());
Set("PI", {CELL_NUMBER, 3.14159265358979f}); Set("PI", {CELL_NUMBER, 3.14159265358979f});
Set("E", {CELL_NUMBER, 2.71828f}); Set("E", {CELL_NUMBER, 2.71828f});
Set("X", {CELL_NUMBER, 0});
Set("Y", {CELL_NUMBER, 1});
// Cons/CAR/CDR // Cons/CAR/CDR
Set("car", FCar()); Set("car", FCar());

View file

@ -116,6 +116,8 @@ ksi::Cell FFillSelection()
XYf p3 = {points[1].x, points[1].z}; XYf p3 = {points[1].x, points[1].z};
XYf p4 = {points[3].x, points[3].z}; XYf p4 = {points[3].x, points[3].z};
int dir = 0;
float nh1 = 0.0f; float nh1 = 0.0f;
float nh2 = 4.0f; float nh2 = 4.0f;
for (const auto& sp: sandbox->map.sectors) for (const auto& sp: sandbox->map.sectors)
@ -156,6 +158,7 @@ ksi::Cell FFillSelection()
p2.y, // y2 p2.y, // y2
nh1, // nh1 nh1, // nh1
nh2, // nh2 nh2, // nh2
dir // dir
}; };
size_t i = 0; size_t i = 0;
@ -389,8 +392,10 @@ void Editor::RenderModeBuild()
if (ImGui::Button("Evaluate")) if (ImGui::Button("Evaluate"))
{ {
std::string txt = build_text_editor.GetText(); std::string txt = build_text_editor.GetText();
kp3d::str::ReplaceAll(txt, "\n", "");
kp3d::console::SendKSI(txt); kp3d::console::SendKSI(txt);
points.clear();
build_has_start_pos = false;
build_show_options = false;
// KP3D_LOG_INFO("EVAL: {}", txt); // KP3D_LOG_INFO("EVAL: {}", txt);
} }
ImGui::PushFont(ImGui::GetIO().Fonts->Fonts[1]); ImGui::PushFont(ImGui::GetIO().Fonts->Fonts[1]);