热更新应该不会成功
parent
5264ddcb83
commit
45521fdee5
|
@ -10,13 +10,14 @@ import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
public class CheckFight {
|
public class CheckFight {
|
||||||
|
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(CheckFight.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(CheckFight.class);
|
||||||
|
|
||||||
private ThreadLocal<LuaValue> localTransCoderObj = new ThreadLocal<LuaValue>();
|
private ThreadLocal<LuaValue> localTransCoderObj = new ThreadLocal<LuaValue>();
|
||||||
|
private ThreadLocal<Integer> localVersion = new ThreadLocal<>();
|
||||||
// private String luaFileName = null;
|
// private String luaFileName = null;
|
||||||
|
|
||||||
private CheckFight(){}
|
private CheckFight(){}
|
||||||
|
@ -29,7 +30,7 @@ public class CheckFight {
|
||||||
return CheckFight.Instance.instance;
|
return CheckFight.Instance.instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int hotFixVersion = 0;
|
private AtomicInteger hotFixVersion = new AtomicInteger();
|
||||||
|
|
||||||
static class LuaHotFixBean{
|
static class LuaHotFixBean{
|
||||||
private int version;
|
private int version;
|
||||||
|
@ -42,21 +43,22 @@ public class CheckFight {
|
||||||
|
|
||||||
public void luaHotFix(){
|
public void luaHotFix(){
|
||||||
LuaHotFixBean luaHotFixBean = STableManager.getJsonFilePathInJsonConf("lua-hotfix.json", LuaHotFixBean.class);
|
LuaHotFixBean luaHotFixBean = STableManager.getJsonFilePathInJsonConf("lua-hotfix.json", LuaHotFixBean.class);
|
||||||
if(luaHotFixBean!=null && hotFixVersion < luaHotFixBean.getVersion()){
|
if(luaHotFixBean!=null && hotFixVersion.get() < luaHotFixBean.getVersion()){
|
||||||
LOGGER.info("the curhotFixVersion={},the new hotFixVersion={} will hotfix ",hotFixVersion,luaHotFixBean.getVersion());
|
LOGGER.info("the curhotFixVersion={},the new hotFixVersion={} will hotfix ",hotFixVersion.get(),luaHotFixBean.getVersion());
|
||||||
init();
|
//init();
|
||||||
LOGGER.info("the luahotfix done");
|
LOGGER.info("the luahotfix done");
|
||||||
hotFixVersion = luaHotFixBean.getVersion();
|
hotFixVersion.set(luaHotFixBean.getVersion());
|
||||||
|
//tofix 不是原子操作
|
||||||
this.localTransCoderObj = new ThreadLocal<LuaValue>();
|
this.localTransCoderObj = new ThreadLocal<LuaValue>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void init(){
|
// public void init(){
|
||||||
LuaHotFixBean luaHotFixBean = STableManager.getJsonFilePathInJsonConf("lua-hotfix.json", LuaHotFixBean.class);
|
// LuaHotFixBean luaHotFixBean = STableManager.getJsonFilePathInJsonConf("lua-hotfix.json", LuaHotFixBean.class);
|
||||||
if(luaHotFixBean!=null) {
|
// if(luaHotFixBean!=null) {
|
||||||
hotFixVersion = luaHotFixBean.getVersion();
|
// hotFixVersion = luaHotFixBean.getVersion();
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
public static String getPath(String prefixDir, String... filePath) throws IOException {
|
public static String getPath(String prefixDir, String... filePath) throws IOException {
|
||||||
|
@ -117,13 +119,14 @@ public class CheckFight {
|
||||||
|
|
||||||
public LuaValue getTransCoderObj(){
|
public LuaValue getTransCoderObj(){
|
||||||
LuaValue transCoderObj = localTransCoderObj.get();
|
LuaValue transCoderObj = localTransCoderObj.get();
|
||||||
if(transCoderObj == null){
|
if(transCoderObj == null||localVersion.get()!=hotFixVersion.get()){
|
||||||
String luaFileName = null;
|
String luaFileName = null;
|
||||||
try {
|
try {
|
||||||
luaFileName = getPath("luafight/BattleMain.lua");
|
luaFileName = getPath("luafight/BattleMain.lua");
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
localVersion.set( hotFixVersion.get());
|
||||||
Globals globals = JsePlatform.debugGlobals();
|
Globals globals = JsePlatform.debugGlobals();
|
||||||
transCoderObj = globals.loadfile(luaFileName).call();
|
transCoderObj = globals.loadfile(luaFileName).call();
|
||||||
localTransCoderObj.set(transCoderObj);
|
localTransCoderObj.set(transCoderObj);
|
||||||
|
|
Loading…
Reference in New Issue