mirror of
https://bitbucket.org/projectswg/cucore.git
synced 2026-01-16 23:04:20 -05:00
Refactored buildouts to support loading events
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,152 @@
|
||||
package resources.buildout;
|
||||
|
||||
public class BuildoutArea {
|
||||
import resources.Terrain;
|
||||
|
||||
public class BuildoutArea implements Comparable<BuildoutArea> {
|
||||
|
||||
private int id;
|
||||
private String name;
|
||||
private Terrain terrain;
|
||||
private String event;
|
||||
private double x1;
|
||||
private double z1;
|
||||
private double x2;
|
||||
private double z2;
|
||||
private boolean adjustCoordinates;
|
||||
|
||||
private BuildoutArea() {
|
||||
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public Terrain getTerrain() {
|
||||
return terrain;
|
||||
}
|
||||
|
||||
public String getEvent() {
|
||||
return event;
|
||||
}
|
||||
|
||||
public double getX1() {
|
||||
return x1;
|
||||
}
|
||||
|
||||
public double getZ1() {
|
||||
return z1;
|
||||
}
|
||||
|
||||
public double getX2() {
|
||||
return x2;
|
||||
}
|
||||
|
||||
public double getZ2() {
|
||||
return z2;
|
||||
}
|
||||
|
||||
public boolean isAdjustCoordinates() {
|
||||
return adjustCoordinates;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return terrain.hashCode() ^ Double.hashCode(x1) ^ Double.hashCode(z1);
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if (o == null || !(o instanceof BuildoutArea))
|
||||
return false;
|
||||
BuildoutArea area = (BuildoutArea) o;
|
||||
if (!terrain.equals(area.terrain))
|
||||
return false;
|
||||
if (x1 != area.x1)
|
||||
return false;
|
||||
if (z1 != area.z1)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public int compareTo(BuildoutArea area) {
|
||||
int comp = terrain.getName().compareTo(area.terrain.getName());
|
||||
if (comp != 0)
|
||||
return comp;
|
||||
comp = Double.compare(x1, area.x1);
|
||||
if (comp != 0)
|
||||
return comp;
|
||||
comp = Double.compare(z1, area.z1);
|
||||
if (comp != 0)
|
||||
return comp;
|
||||
comp = Double.compare(x2, area.x2);
|
||||
if (comp != 0)
|
||||
return comp;
|
||||
comp = Double.compare(z2, area.z2);
|
||||
if (comp != 0)
|
||||
return comp;
|
||||
return 0;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return String.format("%s %s: %.1f, %.1f/%.1f, %.1f", name, terrain.getName(), x1, z1, x2, z2);
|
||||
}
|
||||
|
||||
public static class BuildoutAreaBuilder {
|
||||
|
||||
private final BuildoutArea area = new BuildoutArea();
|
||||
|
||||
public BuildoutAreaBuilder setId(int id) {
|
||||
area.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public BuildoutAreaBuilder setName(String name){
|
||||
area.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public BuildoutAreaBuilder setTerrain(Terrain terrain) {
|
||||
area.terrain = terrain;
|
||||
return this;
|
||||
}
|
||||
|
||||
public BuildoutAreaBuilder setEvent(String event) {
|
||||
area.event = event;
|
||||
return this;
|
||||
}
|
||||
|
||||
public BuildoutAreaBuilder setX1(double x1) {
|
||||
area.x1 = x1;
|
||||
return this;
|
||||
}
|
||||
|
||||
public BuildoutAreaBuilder setZ1(double z1) {
|
||||
area.z1 = z1;
|
||||
return this;
|
||||
}
|
||||
|
||||
public BuildoutAreaBuilder setX2(double x2) {
|
||||
area.x2 = x2;
|
||||
return this;
|
||||
}
|
||||
|
||||
public BuildoutAreaBuilder setZ2(double z2) {
|
||||
area.z2 = z2;
|
||||
return this;
|
||||
}
|
||||
|
||||
public BuildoutAreaBuilder setAdjustCoordinates(boolean adjustCoordinates) {
|
||||
area.adjustCoordinates = adjustCoordinates;
|
||||
return this;
|
||||
}
|
||||
|
||||
public BuildoutArea build() {
|
||||
return area;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -39,6 +39,7 @@ import network.packets.swg.zone.object_controller.DataTransform;
|
||||
import network.packets.swg.zone.object_controller.DataTransformWithParent;
|
||||
import resources.Location;
|
||||
import resources.Terrain;
|
||||
import resources.buildout.BuildoutArea;
|
||||
import resources.common.CRC;
|
||||
import resources.containers.ContainerPermissions;
|
||||
import resources.containers.ContainerResult;
|
||||
@@ -79,6 +80,7 @@ public abstract class SWGObject implements Serializable, Comparable<SWGObject> {
|
||||
private final BaselineType objectType;
|
||||
private ContainerPermissions containerPermissions;
|
||||
private transient Set <SWGObject> objectsAware;
|
||||
private transient BuildoutArea buildoutArea;
|
||||
private List <List <String>> arrangement;
|
||||
|
||||
private Player owner = null;
|
||||
@@ -114,8 +116,10 @@ public abstract class SWGObject implements Serializable, Comparable<SWGObject> {
|
||||
}
|
||||
|
||||
private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException {
|
||||
areaId = -1;
|
||||
ois.defaultReadObject();
|
||||
objectsAware = new HashSet<SWGObject>();
|
||||
buildoutArea = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -402,10 +406,18 @@ public abstract class SWGObject implements Serializable, Comparable<SWGObject> {
|
||||
this.complexity = complexity;
|
||||
}
|
||||
|
||||
public void setAreaId(int areaId) {
|
||||
public void setBuildoutArea(BuildoutArea buildoutArea) {
|
||||
this.buildoutArea = buildoutArea;
|
||||
}
|
||||
|
||||
public void setBuildoutAreaId(int areaId) {
|
||||
this.areaId = areaId;
|
||||
}
|
||||
|
||||
public void setArrangement(List<List<String>> arrangement) {
|
||||
this.arrangement = arrangement;
|
||||
}
|
||||
|
||||
public Player getOwner() {
|
||||
if (owner != null)
|
||||
return owner;
|
||||
@@ -483,7 +495,11 @@ public abstract class SWGObject implements Serializable, Comparable<SWGObject> {
|
||||
return complexity;
|
||||
}
|
||||
|
||||
public int getAreaId() {
|
||||
public BuildoutArea getBuildoutArea() {
|
||||
return buildoutArea;
|
||||
}
|
||||
|
||||
public int getBuildoutAreaId() {
|
||||
return areaId;
|
||||
}
|
||||
|
||||
@@ -499,10 +515,6 @@ public abstract class SWGObject implements Serializable, Comparable<SWGObject> {
|
||||
return arrangement;
|
||||
}
|
||||
|
||||
public void setArrangement(List<List<String>> arrangement) {
|
||||
this.arrangement = arrangement;
|
||||
}
|
||||
|
||||
public String getAttribute(String attribute) {
|
||||
return attributes.get(attribute);
|
||||
}
|
||||
@@ -683,17 +695,18 @@ public abstract class SWGObject implements Serializable, Comparable<SWGObject> {
|
||||
}
|
||||
|
||||
private boolean isValidPlayer(Player player) {
|
||||
if (player == null || player == getOwner())
|
||||
return false;
|
||||
if (getOwner() == null)
|
||||
return false;
|
||||
if (player.equals(getOwner()))
|
||||
Player owner = getOwner();
|
||||
if (player == null || player == owner)
|
||||
return false;
|
||||
if (player.getCreatureObject() == null)
|
||||
return false;
|
||||
if (player.getCreatureObject().getPlayerObject() == null)
|
||||
return false;
|
||||
SWGObject creature = getOwner().getCreatureObject();
|
||||
if (player.equals(owner))
|
||||
return false;
|
||||
if (owner == null)
|
||||
return false;
|
||||
SWGObject creature = owner.getCreatureObject();
|
||||
if (creature == null)
|
||||
return false;
|
||||
if (player.getCreatureObject().equals(creature))
|
||||
|
||||
@@ -79,8 +79,6 @@ class TerrainBuildoutLoader {
|
||||
for (int row = 0; row < areaTable.getRowCount(); row++) {
|
||||
SwgBuildoutArea area = new SwgBuildoutArea();
|
||||
area.load(areaTable.getRow(row), sceneNumber, row);
|
||||
if (!area.getName().startsWith(terrain.getName()))
|
||||
continue;
|
||||
loadArea(area);
|
||||
}
|
||||
}
|
||||
@@ -94,7 +92,7 @@ class TerrainBuildoutLoader {
|
||||
SWGObject object = createObject(buildoutRow);
|
||||
object.setBuildout(true);
|
||||
object.setLoadRange(buildoutRow.getRadius());
|
||||
object.setAreaId(area.getIndex());
|
||||
object.setBuildoutAreaId(area.getIndex());
|
||||
setCellInformation(object, buildoutRow.getCellIndex());
|
||||
addObject(object, buildoutRow.getContainerId());
|
||||
updatePermissions(object);
|
||||
|
||||
@@ -78,8 +78,8 @@ public class TerrainSnapshotLoader {
|
||||
private void createFromNode(Map<Integer, String> templates, Node node) {
|
||||
SWGObject object = createObject(templates, node);
|
||||
object.setBuildout(true);
|
||||
object.setBuildoutAreaId(-1);
|
||||
object.setLoadRange(node.getRadius());
|
||||
object.setAreaId(-1);
|
||||
setCellInformation(object, node.getCellIndex());
|
||||
addObject(object, node.getContainerId());
|
||||
updatePermissions(object);
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
package services.objects;
|
||||
|
||||
import intents.player.PlayerTransformedIntent;
|
||||
import resources.control.Intent;
|
||||
import resources.control.Service;
|
||||
import resources.server_info.RelationalServerData;
|
||||
|
||||
public class BuildoutAreaService extends Service {
|
||||
|
||||
private static final String FILE_PREFIX = "serverdata/buildout/";
|
||||
|
||||
private final RelationalServerData clientSdb;
|
||||
|
||||
public BuildoutAreaService() {
|
||||
clientSdb = new RelationalServerData(FILE_PREFIX+"buildouts.db");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean initialize() {
|
||||
registerForIntent(PlayerTransformedIntent.TYPE);
|
||||
boolean success = clientSdb.linkTableWithSdb("areas", FILE_PREFIX+"areas.sdb");
|
||||
return super.initialize() && success;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onIntentReceived(Intent i) {
|
||||
switch (i.getType()) {
|
||||
case PlayerTransformedIntent.TYPE:
|
||||
if (i instanceof PlayerTransformedIntent)
|
||||
handlePlayerTransform((PlayerTransformedIntent) i);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void handlePlayerTransform(PlayerTransformedIntent pti) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
308
src/services/objects/ClientBuildoutService.java
Normal file
308
src/services/objects/ClientBuildoutService.java
Normal file
@@ -0,0 +1,308 @@
|
||||
package services.objects;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Hashtable;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import intents.player.PlayerTransformedIntent;
|
||||
import resources.Location;
|
||||
import resources.Terrain;
|
||||
import resources.buildout.BuildoutArea;
|
||||
import resources.buildout.BuildoutArea.BuildoutAreaBuilder;
|
||||
import resources.client_info.ClientFactory;
|
||||
import resources.client_info.visitors.CrcStringTableData;
|
||||
import resources.config.ConfigFile;
|
||||
import resources.control.Intent;
|
||||
import resources.control.Service;
|
||||
import resources.objects.SWGObject;
|
||||
import resources.objects.cell.CellObject;
|
||||
import resources.objects.creature.CreatureObject;
|
||||
import resources.server_info.Config;
|
||||
import resources.server_info.Log;
|
||||
import resources.server_info.RelationalServerData;
|
||||
import resources.server_info.RelationalServerFactory;
|
||||
|
||||
public class ClientBuildoutService extends Service {
|
||||
|
||||
private static final String GET_BUILDOUT_AREAS = "SELECT * FROM areas ORDER BY area_name ASC, event ASC";
|
||||
private static final String GET_CLIENT_OBJECTS_SQL = "SELECT objects.*, areas.terrain "
|
||||
+ "FROM objects, areas "
|
||||
+ "WHERE objects.area_id = areas.id "
|
||||
+ "ORDER BY buildout_id ASC";
|
||||
|
||||
private final CrcStringTableData strings;
|
||||
private final RelationalServerData clientSdb;
|
||||
private final List<BuildoutArea> areas;
|
||||
private final Map<Integer, BuildoutArea> areasById;
|
||||
private final PreparedStatement getClientObjects;
|
||||
|
||||
public ClientBuildoutService() {
|
||||
strings = (CrcStringTableData) ClientFactory.getInfoFromFile("misc/object_template_crc_string_table.iff");
|
||||
clientSdb = RelationalServerFactory.getServerData("buildout/buildouts.db", "areas", "objects");
|
||||
if (clientSdb == null)
|
||||
throw new main.ProjectSWG.CoreException("Unable to load sdb files for ClientObjectLoader");
|
||||
areas = new ArrayList<>();
|
||||
areasById = new Hashtable<>(1000); // Number of buildout areas
|
||||
|
||||
getClientObjects = clientSdb.prepareStatement(GET_CLIENT_OBJECTS_SQL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean initialize() {
|
||||
registerForIntent(PlayerTransformedIntent.TYPE);
|
||||
List<String> events = getEvents();
|
||||
loadAreas(events);
|
||||
return super.initialize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onIntentReceived(Intent i) {
|
||||
switch (i.getType()) {
|
||||
case PlayerTransformedIntent.TYPE:
|
||||
if (i instanceof PlayerTransformedIntent)
|
||||
handlePlayerTransform((PlayerTransformedIntent) i);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public Map<Long, SWGObject> loadClientObjects() {
|
||||
Config c = getConfig(ConfigFile.PRIMARY);
|
||||
if (c.getBoolean("LOAD-OBJECTS", true)) {
|
||||
System.out.println("ClientBuildoutService: Loading client objects...");
|
||||
Log.i("ClientBuildoutService", "Loading client objects...");
|
||||
long startLoad = System.nanoTime();
|
||||
Map<Long, SWGObject> objects = new Hashtable<>(4*1024);
|
||||
loadClientObjects(objects);
|
||||
double loadTime = (System.nanoTime() - startLoad) / 1E6;
|
||||
System.out.printf("ClientObjectLoader: Finished loading %d client objects. Time: %fms%n", objects.size(), loadTime);
|
||||
Log.i("ClientObjectLoader", "Finished loading %d client objects. Time: %fms", objects.size(), loadTime);
|
||||
return objects;
|
||||
} else {
|
||||
Log.w("ClientObjectLoader", "Did not load client objects. Reason: Disabled.");
|
||||
System.out.println("ClientObjectLoader: Did not load client objects. Reason: Disabled!");
|
||||
}
|
||||
return new HashMap<>();
|
||||
}
|
||||
|
||||
private void loadClientObjects(Map<Long, SWGObject> objects) {
|
||||
try (ResultSet set = getClientObjects.executeQuery()) {
|
||||
set.setFetchSize(1500);
|
||||
BuildoutArea area = null;
|
||||
ColumnIndexes ind = new ColumnIndexes(set);
|
||||
SWGObject obj;
|
||||
Location l = new Location();
|
||||
while (set.next()) {
|
||||
area = areasById.get(ind.areaInd);
|
||||
obj = createObject(set, objects, l, area, ind);
|
||||
objects.put(obj.getObjectId(), obj);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private List<String> getEvents() {
|
||||
List <String> events = new ArrayList<>();
|
||||
String eventStr = getConfig(ConfigFile.FEATURES).getString("EVENTS", "");
|
||||
String [] eventArray = eventStr.split(",");
|
||||
for (String event : eventArray) {
|
||||
event = event.toLowerCase(Locale.US);
|
||||
if (!event.isEmpty())
|
||||
events.add(event);
|
||||
}
|
||||
return events;
|
||||
}
|
||||
|
||||
private SWGObject createObject(ResultSet set, Map<Long, SWGObject> objects, Location l, BuildoutArea area, ColumnIndexes ind) throws SQLException {
|
||||
SWGObject obj = ObjectCreator.createObjectFromTemplate(set.getLong(ind.idInd), strings.getTemplateString(set.getInt(ind.crcInd)));
|
||||
l.setTerrain(Terrain.getTerrainFromName(set.getString(ind.terInd)));
|
||||
l.setPosition(set.getDouble(ind.xInd), set.getDouble(ind.yInd), set.getDouble(ind.zInd));
|
||||
l.setOrientation(set.getDouble(ind.oxInd), set.getDouble(ind.oyInd), set.getDouble(ind.ozInd), set.getDouble(ind.owInd));
|
||||
obj.setLocation(l);
|
||||
obj.setBuildout(true);
|
||||
obj.setBuildoutArea(area);
|
||||
obj.setLoadRange(set.getInt(ind.radiusInd));
|
||||
int cell = set.getInt(ind.cellInd);
|
||||
if (cell != 0 && obj instanceof CellObject)
|
||||
((CellObject) obj).setNumber(cell);
|
||||
long container = set.getLong(ind.contInd);
|
||||
if (container != 0)
|
||||
objects.get(container).addObject(obj);
|
||||
return obj;
|
||||
}
|
||||
|
||||
private void loadAreas(List <String> events) {
|
||||
BuildoutArea primary = null; // Stored as "best area" for what we want to load
|
||||
try (RelationalServerData data = RelationalServerFactory.getServerData("buildout/buildouts.db", "areas")) {
|
||||
try (ResultSet set = data.prepareStatement(GET_BUILDOUT_AREAS).executeQuery()) {
|
||||
areas.clear();
|
||||
areasById.clear();
|
||||
AreaIndexes ind = new AreaIndexes(set);
|
||||
boolean loaded = false;
|
||||
while (set.next()) {
|
||||
BuildoutArea area = createArea(set, ind);
|
||||
if (area.getEvent().isEmpty() && (primary == null || !area.getName().equals(primary.getName()))) {
|
||||
if (!loaded && primary != null)
|
||||
loadArea(primary);
|
||||
loaded = false;
|
||||
primary = area; // Primary area, no event
|
||||
}
|
||||
if (events.contains(area.getEvent())) {
|
||||
loadArea(area);
|
||||
loaded = true;
|
||||
}
|
||||
}
|
||||
if (!loaded && primary != null)
|
||||
loadArea(primary);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void handlePlayerTransform(PlayerTransformedIntent pti) {
|
||||
CreatureObject creature = pti.getPlayer();
|
||||
Location world = creature.getWorldLocation();
|
||||
BuildoutArea area = creature.getBuildoutArea();
|
||||
if (area == null || compare(area, world.getTerrain(), world.getX(), world.getZ()) != 0) {
|
||||
area = getAreaForObject(creature);
|
||||
creature.setBuildoutArea(area);
|
||||
}
|
||||
}
|
||||
|
||||
private void loadArea(BuildoutArea area) {
|
||||
areas.add(area);
|
||||
areasById.put(area.getId(), area);
|
||||
}
|
||||
|
||||
private BuildoutArea createArea(ResultSet set, AreaIndexes ind) throws SQLException {
|
||||
BuildoutAreaBuilder bldr = new BuildoutAreaBuilder()
|
||||
.setId(set.getInt(ind.id))
|
||||
.setName(set.getString(ind.name))
|
||||
.setTerrain(Terrain.getTerrainFromName(set.getString(ind.terrain)))
|
||||
.setEvent(set.getString(ind.event))
|
||||
.setX1(set.getDouble(ind.x1))
|
||||
.setZ1(set.getDouble(ind.z1))
|
||||
.setX2(set.getDouble(ind.x2))
|
||||
.setZ2(set.getDouble(ind.z2))
|
||||
.setAdjustCoordinates(set.getBoolean(ind.adjust));
|
||||
return bldr.build();
|
||||
}
|
||||
|
||||
private BuildoutArea getAreaForObject(SWGObject obj) {
|
||||
Location l = obj.getWorldLocation();
|
||||
return binarySearch(l.getTerrain(), l.getX(), l.getZ());
|
||||
}
|
||||
|
||||
private BuildoutArea binarySearch(Terrain t, double x, double z) {
|
||||
int low = 0;
|
||||
int high = areas.size();
|
||||
int comp = 0;
|
||||
while ((comp = binarySearch(low, high, t, x, z)) != 0 && low != high) {
|
||||
int mid = mid(low, high);
|
||||
if (comp == 0)
|
||||
return areas.get(mid);
|
||||
if (comp < 0) {
|
||||
low = mid;
|
||||
} else {
|
||||
high = mid;
|
||||
}
|
||||
}
|
||||
BuildoutArea area = areas.get(mid(low, high));
|
||||
if (compare(area, t, x, z) == 0)
|
||||
return area;
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
private int binarySearch(int low, int high, Terrain t, double x, double z) {
|
||||
return compare(areas.get(mid(low, high)), t, x, z);
|
||||
}
|
||||
|
||||
private int compare(BuildoutArea cur, Terrain t, double x, double z) {
|
||||
int comp = cur.getTerrain().getName().compareTo(t.getName());
|
||||
if (comp != 0)
|
||||
return comp;
|
||||
if (x < cur.getX1())
|
||||
return 1;
|
||||
if (x > cur.getX2())
|
||||
return -1;
|
||||
if (z < cur.getZ1())
|
||||
return 1;
|
||||
if (z > cur.getZ2())
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
private int mid(int low, int high) {
|
||||
return (low + high) / 2;
|
||||
}
|
||||
|
||||
private static class AreaIndexes {
|
||||
|
||||
private int id;
|
||||
private int name;
|
||||
private int terrain;
|
||||
private int event;
|
||||
private int x1, z1, x2, z2;
|
||||
private int adjust;
|
||||
|
||||
public AreaIndexes(ResultSet set) throws SQLException {
|
||||
id = set.findColumn("id");
|
||||
name = set.findColumn("area_name");
|
||||
terrain = set.findColumn("terrain");
|
||||
event = set.findColumn("event");
|
||||
x1 = set.findColumn("min_x");
|
||||
z1 = set.findColumn("min_z");
|
||||
x2 = set.findColumn("max_x");
|
||||
z2 = set.findColumn("max_z");
|
||||
adjust = set.findColumn("adjust_coordinates");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static class ColumnIndexes {
|
||||
|
||||
public final int idInd;
|
||||
public final int crcInd;
|
||||
public final int terInd;
|
||||
public final int areaInd;
|
||||
public final int xInd;
|
||||
public final int yInd;
|
||||
public final int zInd;
|
||||
public final int oxInd;
|
||||
public final int oyInd;
|
||||
public final int ozInd;
|
||||
public final int owInd;
|
||||
public final int radiusInd;
|
||||
public final int contInd;
|
||||
public final int cellInd;
|
||||
|
||||
public ColumnIndexes(ResultSet set) throws SQLException {
|
||||
idInd = set.findColumn("id");
|
||||
crcInd = set.findColumn("templateCrc");
|
||||
terInd = set.findColumn("terrain");
|
||||
areaInd = set.findColumn("area_id");
|
||||
xInd = set.findColumn("x");
|
||||
yInd = set.findColumn("y");
|
||||
zInd = set.findColumn("z");
|
||||
oxInd = set.findColumn("orientation_x");
|
||||
oyInd = set.findColumn("orientation_y");
|
||||
ozInd = set.findColumn("orientation_z");
|
||||
owInd = set.findColumn("orientation_w");
|
||||
radiusInd = set.findColumn("radius");
|
||||
contInd = set.findColumn("containerId");
|
||||
cellInd = set.findColumn("cellIndex");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,105 +0,0 @@
|
||||
package services.objects;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Map;
|
||||
|
||||
import resources.Location;
|
||||
import resources.Terrain;
|
||||
import resources.client_info.ClientFactory;
|
||||
import resources.client_info.visitors.CrcStringTableData;
|
||||
import resources.objects.SWGObject;
|
||||
import resources.objects.cell.CellObject;
|
||||
import resources.server_info.Log;
|
||||
import resources.server_info.RelationalServerData;
|
||||
import resources.server_info.RelationalServerFactory;
|
||||
|
||||
public class ClientObjectLoader {
|
||||
|
||||
private static final String GET_CLIENT_OBJECTS_SQL = "SELECT objects.*, areas.adjust_coordinates, areas.terrain "
|
||||
+ "FROM objects, areas "
|
||||
+ "WHERE areas.event == '' AND objects.area_id = areas.id "
|
||||
+ "ORDER BY buildout_id ASC";
|
||||
|
||||
private final CrcStringTableData strings;
|
||||
private final RelationalServerData clientSdb;
|
||||
|
||||
public ClientObjectLoader() {
|
||||
strings = (CrcStringTableData) ClientFactory.getInfoFromFile("misc/object_template_crc_string_table.iff");
|
||||
clientSdb = RelationalServerFactory.getServerData("buildout/buildouts.db", "areas", "objects");
|
||||
if (clientSdb == null)
|
||||
throw new main.ProjectSWG.CoreException("Unable to load sdb files for ClientObjectLoader");
|
||||
}
|
||||
|
||||
public Map<Long, SWGObject> loadClientObjects(Terrain terrain) {
|
||||
System.out.println("ClientObjectLoader: Loading client objects...");
|
||||
Log.i("ClientObjectLoader", "Loading client objects...");
|
||||
Map<Long, SWGObject> objects = new Hashtable<>(4*1024);
|
||||
try (ResultSet set = clientSdb.prepareStatement(GET_CLIENT_OBJECTS_SQL).executeQuery()) {
|
||||
set.setFetchSize(1500);
|
||||
ColumnIndexes ind = new ColumnIndexes(set);
|
||||
SWGObject obj;
|
||||
Location l = new Location();
|
||||
while (set.next()) {
|
||||
obj = createObject(set, objects, l, ind);
|
||||
objects.put(obj.getObjectId(), obj);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return objects;
|
||||
}
|
||||
|
||||
private SWGObject createObject(ResultSet set, Map<Long, SWGObject> objects, Location l, ColumnIndexes ind) throws SQLException {
|
||||
SWGObject obj = ObjectCreator.createObjectFromTemplate(set.getLong(ind.idInd), strings.getTemplateString(set.getInt(ind.crcInd)));
|
||||
l.setTerrain(Terrain.getTerrainFromName(set.getString(ind.terInd)));
|
||||
l.setPosition(set.getDouble(ind.xInd), set.getDouble(ind.yInd), set.getDouble(ind.zInd));
|
||||
l.setOrientation(set.getDouble(ind.oxInd), set.getDouble(ind.oyInd), set.getDouble(ind.ozInd), set.getDouble(ind.owInd));
|
||||
obj.setLocation(l);
|
||||
obj.setBuildout(true);
|
||||
obj.setLoadRange(set.getInt(ind.radiusInd));
|
||||
int cell = set.getInt(ind.cellInd);
|
||||
if (cell != 0 && obj instanceof CellObject)
|
||||
((CellObject) obj).setNumber(cell);
|
||||
long container = set.getLong(ind.contInd);
|
||||
if (container != 0)
|
||||
objects.get(container).addObject(obj);
|
||||
return obj;
|
||||
}
|
||||
|
||||
private static class ColumnIndexes {
|
||||
|
||||
public final int idInd;
|
||||
public final int crcInd;
|
||||
public final int terInd;
|
||||
public final int xInd;
|
||||
public final int yInd;
|
||||
public final int zInd;
|
||||
public final int oxInd;
|
||||
public final int oyInd;
|
||||
public final int ozInd;
|
||||
public final int owInd;
|
||||
public final int radiusInd;
|
||||
public final int contInd;
|
||||
public final int cellInd;
|
||||
|
||||
public ColumnIndexes(ResultSet set) throws SQLException {
|
||||
idInd = set.findColumn("id");
|
||||
crcInd = set.findColumn("templateCrc");
|
||||
terInd = set.findColumn("terrain");
|
||||
xInd = set.findColumn("x");
|
||||
yInd = set.findColumn("y");
|
||||
zInd = set.findColumn("z");
|
||||
oxInd = set.findColumn("orientation_x");
|
||||
oyInd = set.findColumn("orientation_y");
|
||||
ozInd = set.findColumn("orientation_z");
|
||||
owInd = set.findColumn("orientation_w");
|
||||
radiusInd = set.findColumn("radius");
|
||||
contInd = set.findColumn("containerId");
|
||||
cellInd = set.findColumn("cellIndex");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -43,8 +43,10 @@ import resources.Terrain;
|
||||
import resources.control.Intent;
|
||||
import resources.control.Service;
|
||||
import resources.objects.SWGObject;
|
||||
import resources.objects.building.BuildingObject;
|
||||
import resources.objects.creature.CreatureObject;
|
||||
import resources.objects.quadtree.QuadTree;
|
||||
import resources.objects.tangible.TangibleObject;
|
||||
import resources.player.Player;
|
||||
|
||||
public class ObjectAwareness extends Service {
|
||||
@@ -114,14 +116,20 @@ public class ObjectAwareness extends Service {
|
||||
|
||||
private void handleObjectCreateIntent(ObjectCreateIntent oci) {
|
||||
SWGObject obj = oci.getObject();
|
||||
if (obj.getParent() == null)
|
||||
add(obj);
|
||||
if (obj.getParent() == null) {
|
||||
if (obj instanceof TangibleObject || obj instanceof BuildingObject) {
|
||||
add(obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void handleObjectCreatedIntent(ObjectCreatedIntent oci) {
|
||||
SWGObject obj = oci.getObject();
|
||||
if (obj.getParent() == null)
|
||||
add(obj);
|
||||
if (obj.getParent() == null) {
|
||||
if (obj instanceof TangibleObject || obj instanceof BuildingObject) {
|
||||
add(obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void loadQuadTree() {
|
||||
|
||||
@@ -56,24 +56,18 @@ import network.packets.swg.zone.object_controller.DataTransform;
|
||||
import network.packets.swg.zone.object_controller.DataTransformWithParent;
|
||||
import network.packets.swg.zone.object_controller.ObjectController;
|
||||
import resources.Location;
|
||||
import resources.Terrain;
|
||||
import resources.config.ConfigFile;
|
||||
import resources.containers.ContainerPermissions;
|
||||
import resources.control.Intent;
|
||||
import resources.control.Manager;
|
||||
import resources.objects.SWGObject;
|
||||
import resources.objects.building.BuildingObject;
|
||||
import resources.objects.creature.CreatureObject;
|
||||
import resources.objects.tangible.TangibleObject;
|
||||
import resources.player.Player;
|
||||
import resources.player.PlayerEvent;
|
||||
import resources.server_info.CachedObjectDatabase;
|
||||
import resources.server_info.Config;
|
||||
import resources.server_info.Log;
|
||||
import resources.server_info.ObjectDatabase;
|
||||
import resources.server_info.ObjectDatabase.Traverser;
|
||||
import services.map.MapManager;
|
||||
import services.map.MapManager.MapType;
|
||||
import services.player.PlayerManager;
|
||||
import services.spawn.SpawnerService;
|
||||
import services.spawn.StaticService;
|
||||
@@ -85,7 +79,7 @@ public class ObjectManager extends Manager {
|
||||
private final StaticService staticService;
|
||||
private final SpawnerService spawnerService;
|
||||
private final RadialService radialService;
|
||||
private final BuildoutAreaService buildoutAreaService;
|
||||
private final ClientBuildoutService clientBuildoutService;
|
||||
|
||||
private final ObjectDatabase<SWGObject> database;
|
||||
private final Map <Long, SWGObject> objectMap;
|
||||
@@ -97,7 +91,7 @@ public class ObjectManager extends Manager {
|
||||
staticService = new StaticService(this);
|
||||
spawnerService = new SpawnerService(this);
|
||||
radialService = new RadialService();
|
||||
buildoutAreaService = new BuildoutAreaService();
|
||||
clientBuildoutService = new ClientBuildoutService();
|
||||
|
||||
database = new CachedObjectDatabase<SWGObject>("odb/objects.db");
|
||||
objectMap = new Hashtable<>(16*1024);
|
||||
@@ -108,7 +102,7 @@ public class ObjectManager extends Manager {
|
||||
addChildService(staticService);
|
||||
addChildService(radialService);
|
||||
addChildService(spawnerService);
|
||||
addChildService(buildoutAreaService);
|
||||
addChildService(clientBuildoutService);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -145,44 +139,18 @@ public class ObjectManager extends Manager {
|
||||
}
|
||||
|
||||
private void loadClientObjects() {
|
||||
long startLoad = System.nanoTime();
|
||||
Config c = getConfig(ConfigFile.PRIMARY);
|
||||
if (c.getBoolean("LOAD-OBJECTS", true)) {
|
||||
String terrainStr = c.getString("LOAD-OBJECTS-FOR", "");
|
||||
Terrain terrain = null;
|
||||
if (Terrain.doesTerrainExistForName(terrainStr))
|
||||
terrain = Terrain.getTerrainFromName(terrainStr);
|
||||
else if (!terrainStr.isEmpty()) {
|
||||
System.err.println("ObjectManager: Unknown terrain '" + terrainStr + "'");
|
||||
Log.e("ObjectManager", "Unknown terrain: %s", terrainStr);
|
||||
long start = System.nanoTime();
|
||||
for (SWGObject obj : clientBuildoutService.loadClientObjects().values()) {
|
||||
synchronized (objectMap) {
|
||||
if (obj.getObjectId() >= maxObjectId) {
|
||||
maxObjectId = obj.getObjectId() + 1;
|
||||
}
|
||||
}
|
||||
ClientObjectLoader loader = new ClientObjectLoader();
|
||||
Map<Long, SWGObject> objects = loader.loadClientObjects(terrain);
|
||||
objectMap.putAll(objects);
|
||||
for (SWGObject obj : objects.values())
|
||||
loadClientObject(obj);
|
||||
double loadTime = (System.nanoTime() - startLoad) / 1E6;
|
||||
System.out.printf("ClientObjectLoader: Finished loading %d client objects. Time: %fms%n", objects.size(), loadTime);
|
||||
Log.i("ClientObjectLoader", "Finished loading %d client objects. Time: %fms", objects.size(), loadTime);
|
||||
} else {
|
||||
Log.w("ObjectManager", "Did not load client objects. Reason: Disabled.");
|
||||
System.out.println("ObjectManager: Did not load client objects. Reason: Disabled!");
|
||||
new ObjectCreatedIntent(obj).broadcast();
|
||||
}
|
||||
}
|
||||
|
||||
private void loadClientObject(SWGObject obj) {
|
||||
if (obj.getParent() == null) {
|
||||
if (obj instanceof TangibleObject || obj instanceof BuildingObject) {
|
||||
objectAwareness.add(obj);
|
||||
}
|
||||
}
|
||||
synchronized (objectMap) {
|
||||
if (obj.getObjectId() >= maxObjectId) {
|
||||
maxObjectId = obj.getObjectId() + 1;
|
||||
}
|
||||
}
|
||||
staticService.createSupportingObjects(obj);
|
||||
mapManager.addMapLocation(obj, MapType.STATIC);
|
||||
double loadTime = (System.nanoTime() - start) / 1E6;
|
||||
System.out.printf("ClientObjectLoader: Finished loading client objects. Time: %fms%n", loadTime);
|
||||
Log.i("ClientObjectLoader", "Finished loading client objects. Time: %fms", loadTime);
|
||||
}
|
||||
|
||||
private void loadObject(SWGObject obj) {
|
||||
|
||||
@@ -79,7 +79,7 @@ public class StaticService extends Service {
|
||||
}
|
||||
}
|
||||
|
||||
public void createSupportingObjects(SWGObject object) {
|
||||
private void createSupportingObjects(SWGObject object) {
|
||||
synchronized (databaseMutex) {
|
||||
try {
|
||||
getSupportingStatement.setString(1, object.getTemplate());
|
||||
|
||||
@@ -72,7 +72,7 @@ public class BuildoutGenerator {
|
||||
for (SWGObject snap : snapshots) {
|
||||
GenBuildoutArea area = getAreaForObject(snap);
|
||||
if (area != null)
|
||||
snap.setAreaId(area.id);
|
||||
snap.setBuildoutAreaId(area.id);
|
||||
}
|
||||
objects.addAll(snapshots);
|
||||
long buildoutId = 1;
|
||||
@@ -139,7 +139,7 @@ public class BuildoutGenerator {
|
||||
Quaternion q = l.getOrientation();
|
||||
double radius = object.getLoadRange();
|
||||
int cellIndex = (object instanceof CellObject) ? ((CellObject) object).getNumber() : 0;
|
||||
gen.writeLine(id, buildoutId, object.getAreaId(), crc, container, l.getX(), l.getY(), l.getZ(), q.getX(), q.getY(), q.getZ(), q.getW(), radius, cellIndex);
|
||||
gen.writeLine(id, buildoutId, object.getBuildoutAreaId(), crc, container, l.getX(), l.getY(), l.getZ(), q.getX(), q.getY(), q.getZ(), q.getW(), radius, cellIndex);
|
||||
}
|
||||
|
||||
private GenBuildoutArea getAreaForObject(SWGObject obj) {
|
||||
@@ -168,6 +168,7 @@ public class BuildoutGenerator {
|
||||
private static class GenBuildoutArea implements Comparable<GenBuildoutArea> {
|
||||
public final SwgBuildoutArea area;
|
||||
public final Terrain terrain;
|
||||
public final int index;
|
||||
public final int x1;
|
||||
public final int z1;
|
||||
public final int x2;
|
||||
@@ -178,6 +179,7 @@ public class BuildoutGenerator {
|
||||
public GenBuildoutArea(SwgBuildoutArea area, Terrain terrain, double x1, double z1, double x2, double z2, int id, boolean adjust) {
|
||||
this.area = area;
|
||||
this.terrain = terrain;
|
||||
this.index = area.getIndex();
|
||||
this.x1 = (int) x1;
|
||||
this.z1 = (int) z1;
|
||||
this.x2 = (int) x2;
|
||||
@@ -187,7 +189,7 @@ public class BuildoutGenerator {
|
||||
}
|
||||
|
||||
public int compareTo(GenBuildoutArea area) {
|
||||
int comp = terrain.getName().compareTo(area.terrain.getName());
|
||||
int comp = Integer.compare(index, area.index);
|
||||
if (comp != 0)
|
||||
return comp;
|
||||
comp = Integer.compare(x1, area.x1);
|
||||
|
||||
Reference in New Issue
Block a user