Skip to content

Commit

Permalink
Fixed a few UI bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
rafa-br34 committed Apr 5, 2024
1 parent 4a368b3 commit 5b18dc5
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 50 deletions.
12 changes: 7 additions & 5 deletions SOURCE/Entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ int main(int ArgCount, const char* ArgValues[]) {

std::cout << "State machine: " << StateMachineToString(StateMachine, "") << '\n';

Vector2<int> CanvasSize(10, 10);//{ 30720, 17280 };
Vector2<int> CanvasSize(1000, 1000);//{ 30720, 17280 };

SimulationState<uint8_t, int> Simulation;
EncoderState Encoder;
Expand All @@ -147,20 +147,22 @@ int main(int ArgCount, const char* ArgValues[]) {
Ants.push_back(Ant<uint8_t>(Center - Vector2(10, 0), Vector2<int8_t>( 1, 0), StateMachine, StateMachineSize));
//*/
auto Center = CanvasSize / Vector2(2, 2);
Simulation.AddAnt(Ant<uint8_t>(Center, Vector2<int8_t>(0, -1), {R,L}, true));

//Simulation.AddAnt(Ant<uint8_t>(Center, Vector2<int8_t>(0, -1), {C,C,C,C,C,C,U,C,C,C,C,C,R45,R,R45,L135,U,C,U,L,L,R135,L45,R45,R,R135,L45,R,R,R45}, true));

Simulation.AddAnt(Ant<uint8_t>(Center, Vector2<int8_t>(0, -1), {R,L,R,R,L,R,R,L,R,R,L,R}, true));
Simulation.AddAnt(Ant<uint8_t>(Center, Vector2<int8_t>(0, -1), {R,L,C}, true));
//Simulation.AddAnt(Ant<uint8_t>(Center, Vector2<int8_t>(0, -1), {R,L,R,R,L,R,R,L,R,R,L,R}, true));
//Simulation.AddAnt(Ant<uint8_t>(Center, Vector2<int8_t>(0, -1), {R,L,C}, true));

// ffmpeg -r 60 -i "Frames/%d.png" -b:v 5M -c:v libx264 -preset veryslow -qp 0 output.mp4
// ffmpeg -r 60 -i "Frames/%d.png" -b:v 5M -c:v libx264 -preset veryslow -qp 0 -s 1920x1920 output.mp4
// ffmpeg -r 60 -i "Frames/%d.png" -b:v 5M -c:v libx264 -preset veryslow -qp 0 -s 1920x1920 -sws_flags neighbor output.mp4
// ffmpeg -r 30 -i "Frames/%d.png" -c:v libx264 -preset veryslow -qp 0 -s 7680x4320 output.mp4
// 1ull * 1000000000ull 1b

size_t Iterations = 1ull * 100ull;
size_t Iterations = 1ull * 16000ull;
double FrameRate = 1.0; // Video frame rate
double Time = 100.0; // Video time
double Time = 1.0; // Video time
size_t Frames = size_t(Time * FrameRate);

size_t CaptureDelta = size_t(double(Iterations) / double(Frames));
Expand Down
46 changes: 25 additions & 21 deletions WEBSITE/Scripts/Main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@


function ReadVec2Input(Item) {
return { X: Number(Item.X.val()), Y: Number(Item.Y.val()) }

}

function SetVec2Input(Item, Value) {
Item.X.val(Value.X)
Item.Y.val(Value.Y)
}


async function Main() {
let MainCanvas = $("#MainCanvas")

Expand Down Expand Up @@ -66,12 +77,9 @@ async function Main() {

let { Size, Ants } = JSON.parse(Serialized)

GridConfig.Size.X.val(Size.X)
GridConfig.Size.Y.val(Size.Y)
SetVec2Input(GridConfig.Size, Size)

console.log(Ants.map(Ant.FromObject))
for (let AntObject of Ants.map(Ant.FromObject)) {
console.log(AntObject)
SimulationObject.TemplateAnts.push(AntObject)
}

Expand Down Expand Up @@ -173,15 +181,13 @@ async function Main() {
}

UnloadSiteLink()
SetEnabled(CloneAnt, Selected)

if (!Selected) { return }
AntObject = ElementToAnt.get(Selected)

Ant_Position.X.val(AntObject.Position.X)
Ant_Position.Y.val(AntObject.Position.Y)

Ant_Direction.X.val(AntObject.Direction.X)
Ant_Direction.Y.val(AntObject.Direction.Y)

SetVec2Input(Ant_Direction, AntObject.Direction)
SetVec2Input(Ant_Position, AntObject.Position)

Ant_StepSize.val(AntObject.StepSize)
Ant_Wrap.prop("checked", AntObject.Wrap)
Expand All @@ -193,11 +199,9 @@ async function Main() {

function UpdateAnt() {
if (!Selected) { return }
AntObject.Position.X = Number(Ant_Position.X.val())
AntObject.Position.Y = Number(Ant_Position.Y.val())

AntObject.Direction.X = Number(Ant_Direction.X.val())
AntObject.Direction.Y = Number(Ant_Direction.Y.val())
AntObject.Direction = ReadVec2Input(Ant_Direction)
AntObject.Position = ReadVec2Input(Ant_Position)

AntObject.StepSize = Number(Ant_StepSize.val())

Expand Down Expand Up @@ -254,8 +258,9 @@ async function Main() {

ElementToAnt.set(NewLabel, NewAnt)

if (!Select) {
SetEnabled(RemoveAnt, true)
SetEnabled(RemoveAnt, true)

if (Select) {
SetEnabled(CloneAnt, true)
AntObject = NewAnt
Selected = NewLabel
Expand Down Expand Up @@ -358,11 +363,10 @@ async function Main() {
}
})

$("#Simulation_Reset").on("click", () => { ReuploadTexture = true; SimulationObject.Reset() })
$("#Simulation_Step").on("click", () => { ReuploadTexture = true; SimulationObject.Update(IPF) })

$("#ResetCamera").on("click", () => { CameraPosition = { X: 0, Y: 0, Z: 0 }; Stats.Camera.html("0, 0, 0") })
$("#SaveImage").on("click", () => { alert("Not yet implemented") })
$("#Simulation_Reset").on("click", () => { ReuploadTexture = true; SimulationObject.Reset() })
$("#Simulation_Step").on("click", () => { ReuploadTexture = true; SimulationObject.Update(IPF) })
$("#ResetCamera").on("click", () => { CameraPosition = { X: 0, Y: 0, Z: 0 }; Stats.Camera.html("0, 0, 0") })
$("#SaveImage").on("click", () => { alert("Not yet implemented") })
}


Expand Down
25 changes: 3 additions & 22 deletions WEBSITE/Shaders/Fragment.frag
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ uniform vec3 u_Position;
out vec4 o_FragColor;

// From vertex shader
in vec4 s_VertexPosition;
in vec2 s_VertexPosition;


#define XOR_SHIFT32(S) S ^= (S << 13); S ^= (S >> 17); S ^= (S << 5);
Expand All @@ -32,28 +32,9 @@ vec3 GetColor(uint S) {
);
}

const float Grid = 10.0;
const bool Antialias = true;

// @todo This shader can be improved by alot (adding antialiasing, better blending, grid when in high zoom, etc)
// @todo This shader can be improved
void main() {
//o_FragColor = vec4(vec2(1.0) - s_VertexPosition.xy, 0.0, 1.0);
o_FragColor = vec4(GetColor(texture(u_Grid, s_VertexPosition.xy).x), 1.0);
//o_FragColor = vec4(s_VertexPosition.x, s_VertexPosition.y, 0.0, 1.0);
//o_FragColor = vec4(GetColor((uint(s_VertexPosition.x * 255.0) << 8) + uint(s_VertexPosition.y * 255.0)));
//o_FragColor = vec4(float(texture(u_Grid, s_VertexPosition.xy).x) / 65535.0, 0.0, 0.0, 1.0);

/*
// Calculate the floating point difference between pixels
vec2 PixelDelta = (s_VertexPosition.xy / u_Position.z) / u_GridSize;
vec2 PixelCoverage = (PixelDelta * u_GridSize);
#define N(X, Y) texelFetch(u_Grid, ivec2(s_VertexPosition.xy * u_GridSize) + ivec2(X, Y), 0).x
#define C(X, Y) GetColor(N(X, Y))
if (Grid > 0.0 && u_Position.z < -0.90 && ivec2(s_VertexPosition.xy * u_GridSize) != ivec2((s_VertexPosition.xy + (PixelDelta / Grid)) * u_GridSize))
o_FragColor = vec4(1.0);
else
o_FragColor = vec4(GetColor(texture(u_Grid, s_VertexPosition.xy).x), 1.0);
*/
}

4 changes: 2 additions & 2 deletions WEBSITE/Shaders/Vertex.vert
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ uniform vec2 u_GridSize;
in vec4 a_VertexPosition;

// To fragment shader
out vec4 s_VertexPosition;
out vec2 s_VertexPosition;

void main() {
vec4 Position = (a_VertexPosition + vec4(u_Position.x, u_Position.y, 0.0, u_Position.z));
Expand All @@ -21,5 +21,5 @@ void main() {
else
gl_Position = Position * vec4(1.0, RY, 1.0, 1.0);

s_VertexPosition = (a_VertexPosition + 1.0) / 2.0;
s_VertexPosition = (a_VertexPosition.xy + 1.0) / 2.0;
}

0 comments on commit 5b18dc5

Please sign in to comment.