我正在寻找一种解决方案,以便在我的 2D 游戏中的等距场景中正确对对象进行排序目前我正在使用这种方法:int itemSortingOrder = - (int) (item.GameObject.transform.parent.trans...
我正在寻找一种解决方案,以便在我的 2D 游戏中的等距场景中正确对对象进行排序
目前我正在使用这种方法:
int itemSortingOrder = - (int) (item.GameObject.transform.parent.transform.position.y * 1000);
但问题是,它 transform.position
被存储为 WorldCoordinates,当单个单元格周围的几面墙具有相同的坐标时,就会导致问题。我通过不仅计算项目的位置,还添加对象的“边界”来解决了这个问题:
但我觉得我选择了错误的方法,应该以其他方式解决这个问题。
您能就场景中物体的排序方法提供一些建议吗?
我在 Ubuntu 上有一个 java Spring boot 应用程序,它(主要)运行良好。但是,如果我访问一个调用控制器的网站 - 数据被获取,网站被显示,但几秒钟后 - 该应用程序被杀死......
我在 Ubuntu 上有一个 java Spring boot 应用程序,它(主要)运行良好。
但是,如果我访问一个调用控制器的网站 - 数据被获取,网站被显示,但几秒钟后 - 应用程序被杀死!(ps -ef 不显示应用程序,控制器都死了)。
我试图在这个类中捕捉 Spring 关闭操作:
@Slf4j
@Component
public class AlpacaServiceLifeCycle implements CommandLineRunner {
@Override
public void run(String... arg0) throws Exception {
log.info("###START FROM THE LIFECYCLE###");
}
@PreDestroy
public void onExit() {
log.info("###STOP FROM THE LIFECYCLE###");
new Exception().printStackTrace();
}
}
还有这个类:
@Component
public class ContextClosedEventListener {
@EventListener(ContextClosedEvent.class)
public void onContextClosedEvent(ContextClosedEvent contextClosedEvent) {
System.out.println("ContextClosedEvent occurred at millis: " + contextClosedEvent.getTimestamp());
new Exception().printStackTrace();
}
}
此外,有问题的类实现了SmartLifecycle。
但仍然什么也没有显示!
如果应用程序内存不足,则会抛出异常并创建文件告诉我发生了什么。但这里不是(您可以看到数据保存在表中 - 表大小(一行)为 0.02MB)。
会不会是 ubuntu 以某种方式杀死了该应用程序?
有问题的控制器:
@Slf4j
@RestController
@RequestMapping("/positions")
public class PositionsController implements SmartLifecycle {
private static final String BODY_HTML_END = "\t</body>\n" +
"</html>";
private static final String alpacaLink = "https://app.alpaca.markets/trade/{*}";
@Autowired
private PositionsFetchService positionsFetchService;
@Autowired
private SellStocksDailyIndicatorScheduler sellStocksDailyIndicator;
@Autowired
private DailyPurchaseLogCache dailyPurchaseLogCache;
@Resource
private PositionTableRepository positionTableRepository;
@RequestMapping(value = "/list", method = RequestMethod.GET, produces = {MediaType.TEXT_HTML_VALUE})
@ResponseStatus(HttpStatus.OK)
public String list(@RequestParam(name = "soa", required = false) Boolean showOnlyAvailable) throws Exception {
log.info("Positions called");
if (positionTableRepository.findByFetchDate(LocalDate.now()) != null) {
log.info("Fetching from DB");
return positionTableRepository.findByFetchDate(LocalDate.now()).getTableStr();
}
Set<OutptOrderEntity> allOrders = dailyPurchaseLogCache.fetchAllOrders(false);
StringBuilder theTable = new StringBuilder(CONSTANT_VISIBLE_HEADERS + "\t\t<table class=\"sortable\">");
theTable = new StringBuilder(theTable.toString().replace("*TITLE*", "Positions"));
theTable.append("\t\t<th>#</th>\n");
theTable.append("\t\t<th>Created At</th>\n");
theTable.append("\t\t<th>symbol</th>\n");
theTable.append("\t\t<th>avg_entry_price</th>\n");
theTable.append("\t\t<th>current_price</th>\n");
theTable.append("\t\t<th>qty_available</th>\n");
theTable.append("\t\t<th>cost_basis</th>\n");
theTable.append("\t\t<th>market_value</th>\n");
theTable.append("\t\t<th>diff</th>\n");
theTable.append("\t\t<th>change_today</th>\n");
theTable.append("\t\t<th>lastday_price</th>\n");
theTable.append("\t\t<th>qty</th>\n");
theTable.append("\t\t<th>unrealized_pl</th>\n");
List<PositionEntity> positionEntities = positionsFetchService.fetch();
for (int i = 0; i < positionEntities.size(); i++) {
PositionEntity curr = positionEntities.get(i);
if (curr.getAvg_entry_price() != null && curr.getCurrent_price() != null) {
try {
String symbol = curr.getSymbol();
List<OutptOrderEntity> ordersOfSymbol = allOrders.stream().filter(s -> s.getSymbol().equals(symbol)).collect(Collectors.toList());
if (ordersOfSymbol.isEmpty()) {
log.warn("Symbol {} doesn't have data", symbol);
continue;
}
LocalDateTime createdAt = ordersOfSymbol.get(ordersOfSymbol.size() - 1).getCreated_at();
if (showOnlyAvailable && Float.parseFloat(curr.getQty_available()) > 0f) {
theTable.append(new TableData(false, alpacaLink.replace("{*}", curr.getSymbol()),
i + 1, createdAt, curr.getSymbol(), curr.getAvg_entry_price(), curr.getCurrent_price(), curr.getQty_available(), curr.getCost_basis(), curr.getMarket_value(),
Float.parseFloat(curr.getMarket_value()) - Float.parseFloat(curr.getCost_basis()), curr.getChange_today(), curr.getLastday_price(), curr.getQty(), curr.getUnrealized_pl()).
createString(Float.parseFloat(curr.getCurrent_price()) > Float.parseFloat(curr.getAvg_entry_price())));
} else if (!showOnlyAvailable) {
theTable.append(new TableData(false, alpacaLink.replace("{*}", symbol),
i + 1, createdAt, curr.getSymbol(), curr.getAvg_entry_price(), curr.getCurrent_price(), curr.getQty_available(), curr.getCost_basis(), curr.getMarket_value(),
Float.parseFloat(curr.getMarket_value()) - Float.parseFloat(curr.getCost_basis()), curr.getChange_today(), curr.getLastday_price(),
curr.getQty(), curr.getUnrealized_pl()). createString(Float.parseFloat(curr.getCurrent_price()) > Float.parseFloat(curr.getAvg_entry_price())));
}
} catch (Exception e) {
log.error(e.toString(), e);
}
}
}
theTable.append("\t\t\t<script src=\"https://www.kryogenix.org/code/browser/sorttable/sorttable.js\"></script>");
theTable.append("\n\t\t</table>\n");
theTable.append(BODY_HTML_END);
log.info("Fetched all positions");
positionTableRepository.save(new PositionsTableEntity(theTable.toString()));
return theTable.toString();
}
@RequestMapping(value = "/sell_qty_exists", method = RequestMethod.GET, produces = {MediaType.TEXT_HTML_VALUE})
@ResponseStatus(HttpStatus.OK)
public void sellQtyExists() throws Exception {
sellStocksDailyIndicator.scalpOnAllIndicators();
}
@Override public boolean isAutoStartup() {
return false;
}
@Override public void stop(Runnable runnable) {
new Exception().printStackTrace();
}
@Override public void start() {
}
@Override public void stop() {
new Exception().printStackTrace();
}
@Override public boolean isRunning() {
return false;
}
@Override public int getPhase() {
return 0;
}
}