Skip to content

Commit

Permalink
improve session card, bubbles
Browse files Browse the repository at this point in the history
  • Loading branch information
pdtxie committed Mar 22, 2024
1 parent 64934cc commit 4b4266c
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 65 deletions.
4 changes: 2 additions & 2 deletions CubeTime/3rdparty-Bridging-Header.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifndef Bridging_Header_h
#define Bridging_Header_h

//#import "graal_isolate.h"
//#import "org.worldcubeassociation.tnoodle.scrambles.main.h"
#import "graal_isolate.h"
#import "org.worldcubeassociation.tnoodle.scrambles.main.h"
#import "getBestAverage.h++"

#endif /* Bridging_Header_h */
46 changes: 23 additions & 23 deletions CubeTime/Sessions/Tools/ScrambleGeneratorTool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,28 +44,28 @@ class ScrambleThread: Thread {


// graal_create_isolate(nil, &isolate, &thread)
// graal_attach_thread(isolate, &thread)
// while (true) {
// let s = String(cString: tnoodle_lib_scramble(thread, scrType))
//
// if isCancelled {
// break
// }
// semaphore.wait()
// if scrGen.scrambles.unsafelyUnwrapped.count < count {
// DispatchQueue.main.async { [self] in
// scrGen.scrambles!.append(s)
// semaphore.signal()
// }
// } else {
// semaphore.signal()
// break
// }
// }
//
graal_attach_thread(isolate, &thread)
while (true) {
let s = String(cString: tnoodle_lib_scramble(thread, scrType))

if isCancelled {
break
}
semaphore.wait()
if scrGen.scrambles.unsafelyUnwrapped.count < count {
DispatchQueue.main.async { [self] in
scrGen.scrambles!.append(s)
semaphore.signal()
}
} else {
semaphore.signal()
break
}
}

// graal_tear_down_isolate(thread);
// graal_detach_thread(thread)
// waiter.leave()
graal_detach_thread(thread)
waiter.leave()

#if DEBUG
NSLog("SCRAMBLETHREAD: THREAD DONE")
Expand Down Expand Up @@ -101,7 +101,7 @@ class ScrambleGenerator: ObservableObject {

self.scrambles = []

// graal_create_isolate(nil, &isolate, &thread)
graal_create_isolate(nil, &isolate, &thread)

self.threads = (0..<ProcessInfo.processInfo.processorCount).map {_ in
let t = ScrambleThread(isolate: isolate, semaphore: semaphore, scrGen: self, count: numScramble!, scrType: Int32(scrambleType))
Expand All @@ -115,7 +115,7 @@ class ScrambleGenerator: ObservableObject {
self.threads?.forEach({
$0.cancel()
})
// graal_tear_down_isolate(thread)
graal_tear_down_isolate(thread)
}
}

Expand Down
44 changes: 21 additions & 23 deletions CubeTime/StopwatchManager/ScrambleController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,17 @@ class ScrambleController: ObservableObject {
}

func safeGetScramble() -> String {
// var isolate: OpaquePointer? = nil
// var thread: OpaquePointer? = nil
//
//
// graal_create_isolate(nil, &isolate, &thread)
//
// let s = String(cString: tnoodle_lib_scramble(thread, scrambleType))
//
// graal_tear_down_isolate(thread);
//
// return s
return ""
var isolate: OpaquePointer? = nil
var thread: OpaquePointer? = nil


graal_create_isolate(nil, &isolate, &thread)

let s = String(cString: tnoodle_lib_scramble(thread, scrambleType))

graal_tear_down_isolate(thread);

return s
}


Expand All @@ -63,17 +62,16 @@ class ScrambleController: ObservableObject {



// graal_create_isolate(nil, &isolate, &thread)
//
// var svg: String!
//
// scramble.withCString { s in
// svg = String(cString: tnoodle_lib_draw_scramble(thread, scrTypeAtWorkStart, s))
// }
//
// graal_tear_down_isolate(thread);
//
var svg = ""
graal_create_isolate(nil, &isolate, &thread)

var svg: String!

scramble.withCString { s in
svg = String(cString: tnoodle_lib_draw_scramble(thread, scrTypeAtWorkStart, s))
}

graal_tear_down_isolate(thread);


DispatchQueue.main.async {
self.scrambleSVG = svg
Expand Down
33 changes: 16 additions & 17 deletions CubeTime/Timer/ScrambleView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,22 @@ struct AsyncSVGView: View {



// graal_create_isolate(nil, &isolate, &thread)
//
// var svg: String!
//
// #warning("todo: infinite loading if :boom:")
// scramble.withCString { s in
// if let drawnSvg = tnoodle_lib_draw_scramble(thread, puzzle, s) {
// svg = String(cString: drawnSvg)
// } else {
// svg = nil
// }
// }
//
// graal_tear_down_isolate(thread);
//
// return svg
return ""
graal_create_isolate(nil, &isolate, &thread)

var svg: String!

#warning("todo: infinite loading if :boom:")
scramble.withCString { s in
if let drawnSvg = tnoodle_lib_draw_scramble(thread, puzzle, s) {
svg = String(cString: drawnSvg)
} else {
svg = nil
}
}

graal_tear_down_isolate(thread);

return svg
}
let result = await task.result
svg = try? result.get()
Expand Down
1 change: 1 addition & 0 deletions CubeTimeTests/StopwatchManagerStatsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ struct TestSolveWrapper {
solveItem.scramble = "Scramble"
solveItem.session = session
solveItem.scrambleType = 1
solveItem.scrambleSubtype = 0
return solveItem
}
}
Expand Down

0 comments on commit 4b4266c

Please sign in to comment.