Skip to content

Commit 1018bd3

Browse files
committed
фикс автосинхронизации воркспейса и остановки на паузу рендера при сворачивании окна
1 parent f959808 commit 1018bd3

File tree

8 files changed

+113
-60
lines changed

8 files changed

+113
-60
lines changed

build-native.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@
127127
name="jME3-SpaceShift-Editor"
128128
mainClass="com.ss.editor.Starter"
129129
toolkit="fx"
130-
version="0.7.4"
130+
version="0.7.5"
131131
/>
132132

133133
<mkdir dir="build/classes/META-INF"/>
@@ -140,7 +140,7 @@
140140
<manifest>
141141
<attribute name="Implementation-Vendor" value="spaceshift.ru"/>
142142
<attribute name="Implementation-Title" value="jME3 SpaceShift Editor"/>
143-
<attribute name="Implementation-Version" value="0.7.4"/>
143+
<attribute name="Implementation-Version" value="0.7.5"/>
144144
</manifest>
145145
</fx:jar>
146146

build/package/linux/control

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Package: jme3-spaceshift-editor
2-
Version: 0.7.4
2+
Version: 0.7.5
33
Section: tool
44
Maintainer: spaceshift.ru <[email protected]>
55
Priority: optional

src/com/ss/editor/Editor.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
import com.ss.editor.manager.WorkspaceManager;
3737
import com.ss.editor.ui.builder.EditorFXSceneBuilder;
3838
import com.ss.editor.ui.cursor.UbuntuCursorProvider;
39+
import com.ss.editor.ui.event.FXEventManager;
40+
import com.ss.editor.ui.event.impl.WindowChangeFocusEvent;
3941
import com.ss.editor.ui.scene.EditorFXScene;
4042
import com.ss.editor.ui.util.UIUtils;
4143
import com.sun.javafx.cursor.CursorType;
@@ -334,6 +336,28 @@ public long trySyncLock() {
334336
return lock.tryWriteLock();
335337
}
336338

339+
@Override
340+
public void loseFocus() {
341+
super.loseFocus();
342+
343+
final WindowChangeFocusEvent event = new WindowChangeFocusEvent();
344+
event.setFocused(false);
345+
346+
FXEventManager eventManager = FXEventManager.getInstance();
347+
eventManager.notify(event);
348+
}
349+
350+
@Override
351+
public void gainFocus() {
352+
super.gainFocus();
353+
354+
final WindowChangeFocusEvent event = new WindowChangeFocusEvent();
355+
event.setFocused(true);
356+
357+
FXEventManager eventManager = FXEventManager.getInstance();
358+
eventManager.notify(event);
359+
}
360+
337361
@Override
338362
public void update() {
339363

src/com/ss/editor/config/Config.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public abstract class Config {
2020
public static final String CONFIG_RESOURCE_PATH = "/com/ss/editor/config/config.xml";
2121

2222
public static final String TITLE = "jME3 SpaceShift Editor";
23-
public static final String VERSION = "v.0.7.4";
23+
public static final String VERSION = "v.0.7.5";
2424

2525
public static final String SS_FOLDER_IN_USER_HOME = ".jme3-spaceshift-editor";
2626

src/com/ss/editor/config/EditorConfig.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ public AppSettings getSettings() {
304304
settings.setFrequency(displayMode.getRefreshRate());
305305
settings.setGammaCorrection(isGammaCorrection());
306306
settings.setResizable(true);
307+
settings.setFrameRate(90);
307308
// settings.putBoolean("GraphicsDebug", true);
308309

309310
try {

src/com/ss/editor/manager/ResourceManager.java

Lines changed: 59 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import com.ss.editor.ui.event.impl.RequestedRefreshAssetEvent;
1515
import com.ss.editor.util.EditorUtil;
1616
import com.ss.editor.util.SimpleFileVisitor;
17+
import com.ss.editor.util.SimpleFolderVisitor;
1718

1819
import java.io.IOException;
1920
import java.net.URL;
@@ -35,6 +36,7 @@
3536
import rlib.util.ArrayUtils;
3637
import rlib.util.FileUtils;
3738
import rlib.util.StringUtils;
39+
import rlib.util.Util;
3840
import rlib.util.array.Array;
3941
import rlib.util.array.ArrayComparator;
4042
import rlib.util.array.ArrayFactory;
@@ -100,13 +102,14 @@ public static ResourceManager getInstance() {
100102
private final Array<String> materialDefinitions;
101103

102104
/**
103-
* Ключ для слежения за изменением папок.
105+
* Ключи для слежения за изменением папок.
104106
*/
105-
private volatile WatchKey watchKey;
107+
private final Array<WatchKey> watchKeys;
106108

107109
public ResourceManager() {
108110
InitializeManager.valid(getClass());
109111

112+
this.watchKeys = ArrayFactory.newArray(WatchKey.class);
110113
this.classLoaders = ArrayFactory.newArray(URLClassLoader.class);
111114
this.resourcesInClasspath = ArrayFactory.newArray(String.class);
112115
this.materialDefinitionsInClasspath = ArrayFactory.newArray(String.class);
@@ -353,12 +356,9 @@ public Array<String> getAvailableMaterialDefinitions() {
353356
*/
354357
private synchronized void reload() {
355358

356-
final WatchKey currentWatchKey = getWatchKey();
357-
358-
if (currentWatchKey != null) {
359-
currentWatchKey.cancel();
360-
setWatchKey(null);
361-
}
359+
final Array<WatchKey> watchKeys = getWatchKeys();
360+
watchKeys.forEach(WatchKey::cancel);
361+
watchKeys.clear();
362362

363363
final Editor editor = Editor.getInstance();
364364
final AssetManager assetManager = editor.getAssetManager();
@@ -381,13 +381,19 @@ private synchronized void reload() {
381381
}
382382

383383
try {
384-
final WatchKey watchKey = currentAsset.register(WATCH_SERVICE, ENTRY_CREATE, ENTRY_DELETE);
385-
setWatchKey(watchKey);
384+
watchKeys.add(currentAsset.register(WATCH_SERVICE, ENTRY_CREATE, ENTRY_DELETE));
385+
Files.walkFileTree(currentAsset, (SimpleFolderVisitor) (file, attrs) -> registerFolder(watchKeys, file));
386386
} catch (IOException e) {
387387
LOGGER.warning(e);
388388
}
389389
}
390390

391+
private static void registerFolder(final Array<WatchKey> watchKeys, final Path file) {
392+
watchKeys.add(Util.safeExecute(file, first -> {
393+
return first.register(WATCH_SERVICE, ENTRY_CREATE, ENTRY_DELETE);
394+
}));
395+
}
396+
391397
/**
392398
* Обработка файла в папаке asset.
393399
*/
@@ -425,35 +431,71 @@ public void run() {
425431
while (true) {
426432
ThreadUtils.sleep(200);
427433

428-
final WatchKey watchKey = getWatchKey();
429-
final List<WatchEvent<?>> watchEvents = watchKey.pollEvents();
434+
final Array<WatchKey> watchKeys = getWatchKeys();
435+
436+
List<WatchEvent<?>> watchEvents = null;
437+
WatchKey watchKey = null;
438+
439+
synchronized (this) {
440+
for (final WatchKey key : watchKeys) {
441+
watchKey = key;
442+
watchEvents = key.pollEvents();
443+
if (!watchEvents.isEmpty()) break;
444+
}
445+
}
430446

431-
if (watchEvents.isEmpty()) continue;
447+
if (watchEvents == null || watchEvents.isEmpty()) continue;
432448

433449
for (final WatchEvent<?> watchEvent : watchEvents) {
434450

435451
final Path file = (Path) watchEvent.context();
436-
final Path realFile = EditorUtil.getRealFile(file);
452+
final Path folder = (Path) watchKey.watchable();
453+
final Path realFile = folder.resolve(file);
437454

438455
if (watchEvent.kind() == ENTRY_CREATE) {
439456

440457
final CreatedFileEvent event = new CreatedFileEvent();
441458
event.setFile(realFile);
442459
event.setNeedSelect(false);
443460

461+
if (Files.isDirectory(realFile)) {
462+
registerWatchKey(realFile);
463+
}
464+
444465
FX_EVENT_MANAGER.notify(event);
445466

446467
} else if (watchEvent.kind() == ENTRY_DELETE) {
447468

448469
final DeletedFileEvent event = new DeletedFileEvent();
449470
event.setFile(realFile);
450471

472+
removeWatchKeyFor(realFile);
473+
451474
FX_EVENT_MANAGER.notify(event);
452475
}
453476
}
454477
}
455478
}
456479

480+
private synchronized WatchKey findWatchKey(final Path path) {
481+
final Array<WatchKey> watchKeys = getWatchKeys();
482+
return watchKeys.search(path, (toCheck, watchKey) -> watchKey.watchable().equals(toCheck));
483+
}
484+
485+
private synchronized void removeWatchKeyFor(final Path path) {
486+
487+
final WatchKey watchKey = findWatchKey(path);
488+
489+
if (watchKey != null) {
490+
getWatchKeys().fastRemove(watchKey);
491+
watchKey.cancel();
492+
}
493+
}
494+
495+
private synchronized void registerWatchKey(final Path dir) {
496+
Util.safeExecute(() -> getWatchKeys().add(dir.register(WATCH_SERVICE, ENTRY_CREATE, ENTRY_DELETE)));
497+
}
498+
457499
/**
458500
* Обработка обновления Asset.
459501
*/
@@ -469,16 +511,9 @@ private void processChangeAsset() {
469511
}
470512

471513
/**
472-
* @return ключ для слежения за изменением папок.
473-
*/
474-
private WatchKey getWatchKey() {
475-
return watchKey;
476-
}
477-
478-
/**
479-
* @param watchKey ключ для слежения за изменением папок.
514+
* @return ключи для слежения за изменением папок.
480515
*/
481-
private void setWatchKey(final WatchKey watchKey) {
482-
this.watchKey = watchKey;
516+
private Array<WatchKey> getWatchKeys() {
517+
return watchKeys;
483518
}
484519
}

src/com/ss/editor/ui/event/FXEventManager.java

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
package com.ss.editor.ui.event;
22

3-
import com.jme3.system.lwjgl.LwjglWindow;
4-
import com.ss.editor.Editor;
53
import com.ss.editor.manager.ExecutorManager;
6-
import com.ss.editor.ui.event.impl.WindowChangeFocusEvent;
7-
8-
import org.lwjgl.glfw.GLFW;
9-
import org.lwjgl.glfw.GLFWWindowFocusCallback;
104

115
import javafx.application.Platform;
126
import javafx.event.Event;
@@ -36,34 +30,8 @@ public static FXEventManager getInstance() {
3630
*/
3731
private final ObjectDictionary<EventType<? extends Event>, Array<EventHandler<? super Event>>> eventHandlers;
3832

39-
/**
40-
* Слушатель изменения фокуса окна.
41-
*/
42-
private GLFWWindowFocusCallback windowFocusCallback;
43-
4433
public FXEventManager() {
4534
this.eventHandlers = DictionaryFactory.newObjectDictionary();
46-
EXECUTOR_MANAGER.addEditorThreadTask(this::initListener);
47-
}
48-
49-
private void initListener() {
50-
51-
final Editor editor = Editor.getInstance();
52-
final LwjglWindow context = (LwjglWindow) editor.getContext();
53-
54-
windowFocusCallback = new GLFWWindowFocusCallback() {
55-
56-
@Override
57-
public void invoke(final long window, final boolean focused) {
58-
59-
final WindowChangeFocusEvent event = new WindowChangeFocusEvent();
60-
event.setFocused(focused);
61-
62-
FXEventManager.this.notify(event);
63-
}
64-
};
65-
66-
GLFW.glfwSetWindowFocusCallback(context.getWindowHandle(), windowFocusCallback);
6735
}
6836

6937
/**
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.ss.editor.util;
2+
3+
import java.io.IOException;
4+
import java.nio.file.FileVisitResult;
5+
import java.nio.file.Path;
6+
import java.nio.file.attribute.BasicFileAttributes;
7+
8+
/**
9+
* Упрощенная версия визитера по папкам.
10+
*
11+
* @author Ronn
12+
*/
13+
public interface SimpleFolderVisitor extends SimpleFileVisitor {
14+
15+
@Override
16+
public default FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
17+
visit(dir, attrs);
18+
return FileVisitResult.CONTINUE;
19+
}
20+
21+
@Override
22+
public default FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
23+
return FileVisitResult.CONTINUE;
24+
}
25+
}

0 commit comments

Comments
 (0)