game_machine 0.0.11 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +12 -1
- data/Gemfile.lock +32 -47
- data/Rakefile +0 -27
- data/bin/bundle_run.sh +1 -0
- data/bin/game_machine +29 -27
- data/config/cluster.conf +6 -5
- data/config/default.conf +164 -0
- data/config/game_machine.sql +33 -0
- data/config/game_messages.proto +87 -25
- data/config/gamecloud.conf +140 -0
- data/config/messages.proto +46 -53
- data/config/test.conf +149 -0
- data/game_machine.gemspec +10 -5
- data/games/boot.rb +3 -0
- data/games/example/data/game_data.yml +4 -4
- data/games/example/lib/aggressive_npc.rb +1 -1
- data/games/example/lib/game.rb +1 -2
- data/games/example/lib/player_register.rb +1 -1
- data/games/routes.rb +9 -0
- data/games/tutorial/boot.rb +12 -0
- data/games/tutorial/item_manager.rb +256 -0
- data/games/tutorial/object_store.rb +55 -0
- data/games/tutorial/seed.rb +52 -0
- data/games/tutorial/sql_store.rb +30 -0
- data/java/project/build.gradle +134 -0
- data/java/project/component.erb +719 -0
- data/java/{gradle.properties → project/gradle.properties} +1 -1
- data/java/project/gradle/wrapper/gradle-wrapper.jar +0 -0
- data/java/{gradle → project/gradle}/wrapper/gradle-wrapper.properties +2 -2
- data/java/{gradlew → project/gradlew} +0 -0
- data/java/{gradlew.bat → project/gradlew.bat} +0 -0
- data/java/project/local_lib/AdminUi.jar +0 -0
- data/java/{local_lib/protostuff-compiler-1.0.7-jarjar.jar → project/local_lib/protostuff-compiler-1.0.8-jarjar.jar} +0 -0
- data/java/project/local_lib/sigar/libsigar-amd64-freebsd-6.so +0 -0
- data/java/project/local_lib/sigar/libsigar-amd64-linux.so +0 -0
- data/java/project/local_lib/sigar/libsigar-amd64-solaris.so +0 -0
- data/java/project/local_lib/sigar/libsigar-ia64-hpux-11.sl +0 -0
- data/java/project/local_lib/sigar/libsigar-ia64-linux.so +0 -0
- data/java/project/local_lib/sigar/libsigar-pa-hpux-11.sl +0 -0
- data/java/project/local_lib/sigar/libsigar-ppc-aix-5.so +0 -0
- data/java/project/local_lib/sigar/libsigar-ppc-linux.so +0 -0
- data/java/project/local_lib/sigar/libsigar-ppc64-aix-5.so +0 -0
- data/java/project/local_lib/sigar/libsigar-ppc64-linux.so +0 -0
- data/java/project/local_lib/sigar/libsigar-s390x-linux.so +0 -0
- data/java/project/local_lib/sigar/libsigar-sparc-solaris.so +0 -0
- data/java/project/local_lib/sigar/libsigar-sparc64-solaris.so +0 -0
- data/java/project/local_lib/sigar/libsigar-universal-macosx.dylib +0 -0
- data/java/project/local_lib/sigar/libsigar-universal64-macosx.dylib +0 -0
- data/java/project/local_lib/sigar/libsigar-x86-freebsd-5.so +0 -0
- data/java/project/local_lib/sigar/libsigar-x86-freebsd-6.so +0 -0
- data/java/project/local_lib/sigar/libsigar-x86-linux.so +0 -0
- data/java/project/local_lib/sigar/libsigar-x86-solaris.so +0 -0
- data/java/project/local_lib/sigar/sigar-amd64-winnt.dll +0 -0
- data/java/project/local_lib/sigar/sigar-x86-winnt.dll +0 -0
- data/java/project/local_lib/sigar/sigar-x86-winnt.lib +0 -0
- data/java/project/model.erb +99 -0
- data/java/{settings.gradle → project/settings.gradle} +0 -0
- data/java/project/src/main/java/com/game_machine/authentication/DefaultAuthenticator.java +28 -0
- data/java/project/src/main/java/com/game_machine/authentication/PlayerAuthenticator.java +6 -0
- data/java/project/src/main/java/com/game_machine/authentication/PublicAuthenticator.java +20 -0
- data/java/{src → project/src}/main/java/com/game_machine/core/ActorFactory.java +0 -0
- data/java/{src → project/src}/main/java/com/game_machine/core/ActorUtil.java +13 -0
- data/java/project/src/main/java/com/game_machine/core/AuthorizedPlayers.java +23 -0
- data/java/project/src/main/java/com/game_machine/core/ClientMessageDecoder.java +36 -0
- data/java/project/src/main/java/com/game_machine/core/ClientMessageEncoder.java +19 -0
- data/java/project/src/main/java/com/game_machine/core/CloudClient.java +298 -0
- data/java/{src → project/src}/main/java/com/game_machine/core/CommandProxy.java +0 -0
- data/java/project/src/main/java/com/game_machine/core/Commands.java +20 -0
- data/java/project/src/main/java/com/game_machine/core/DatastoreCommands.java +43 -0
- data/java/project/src/main/java/com/game_machine/core/DbConnectionPool.java +72 -0
- data/java/project/src/main/java/com/game_machine/core/DefaultMovementVerifier.java +56 -0
- data/java/{src → project/src}/main/java/com/game_machine/core/EntitySerializer.java +0 -0
- data/java/project/src/main/java/com/game_machine/core/EntityTracking.java +119 -0
- data/java/{src → project/src}/main/java/com/game_machine/core/EventStreamHandler.java +1 -1
- data/java/project/src/main/java/com/game_machine/core/GameActor.java +73 -0
- data/java/project/src/main/java/com/game_machine/core/GameMachineLoader.java +43 -0
- data/java/project/src/main/java/com/game_machine/core/GameMessageActor.java +44 -0
- data/java/project/src/main/java/com/game_machine/core/Grid.java +255 -0
- data/java/{src → project/src}/main/java/com/game_machine/core/GridValue.java +0 -0
- data/java/project/src/main/java/com/game_machine/core/Hashring.java +66 -0
- data/java/{src → project/src}/main/java/com/game_machine/core/IActorFactory.java +0 -0
- data/java/project/src/main/java/com/game_machine/core/LocalLinkedBuffer.java +20 -0
- data/java/project/src/main/java/com/game_machine/core/MessageGateway.java +120 -0
- data/java/project/src/main/java/com/game_machine/core/MessagePersister.java +26 -0
- data/java/project/src/main/java/com/game_machine/core/MonoProxy.java +39 -0
- data/java/project/src/main/java/com/game_machine/core/MovementVerifier.java +7 -0
- data/java/{src → project/src}/main/java/com/game_machine/core/NetMessage.java +10 -6
- data/java/project/src/main/java/com/game_machine/core/PersistentMessage.java +9 -0
- data/java/project/src/main/java/com/game_machine/core/PlayerCommands.java +31 -0
- data/java/project/src/main/java/com/game_machine/core/TcpServer.java +100 -0
- data/java/project/src/main/java/com/game_machine/core/TcpServerHandler.java +54 -0
- data/java/project/src/main/java/com/game_machine/core/TcpServerInitializer.java +32 -0
- data/java/project/src/main/java/com/game_machine/core/UdpClient.java +86 -0
- data/java/{src → project/src}/main/java/com/game_machine/core/UdpServer.java +18 -27
- data/java/{src → project/src}/main/java/com/game_machine/core/UdpServerHandler.java +23 -26
- data/java/project/src/main/java/com/game_machine/core/Vector3.java +159 -0
- data/java/project/src/main/java/com/game_machine/orm/models/PlayerItem.java +118 -0
- data/java/project/src/main/java/com/game_machine/orm/models/TestObject.java +110 -0
- data/java/project/src/main/java/com/game_machine/tutorial/LootGenerator.java +26 -0
- data/java/{src → project/src}/main/resources/game_machine.java.stg +3 -1
- data/java/project/src/main/resources/logback.properties +13 -0
- data/java/project/src/main/resources/logback.xml +76 -0
- data/java/{src → project/src}/main/resources/protostuff.properties +0 -0
- data/java/src/main/java/game/MyGameActor.java +26 -0
- data/lib/game_machine.rb +17 -16
- data/lib/game_machine/actor.rb +1 -1
- data/lib/game_machine/actor/base.rb +8 -31
- data/lib/game_machine/actor/builder.rb +5 -6
- data/lib/game_machine/actor/game_actor.rb +55 -0
- data/lib/game_machine/actor/reloadable.rb +6 -1
- data/lib/game_machine/akka.rb +26 -32
- data/lib/game_machine/app_config.rb +39 -26
- data/lib/game_machine/application.rb +56 -62
- data/lib/game_machine/client_manager.rb +14 -8
- data/lib/game_machine/cloud_updater.rb +51 -0
- data/lib/game_machine/cluster_monitor.rb +3 -3
- data/lib/game_machine/commands.rb +1 -1
- data/lib/game_machine/commands/misc_commands.rb +4 -8
- data/lib/game_machine/commands/player_commands.rb +8 -0
- data/lib/game_machine/console.rb +1 -0
- data/lib/game_machine/console/build.rb +57 -24
- data/lib/game_machine/console/bundle.rb +95 -0
- data/lib/game_machine/console/deploy.rb +30 -0
- data/lib/game_machine/console/install.rb +70 -36
- data/lib/game_machine/console/server.rb +2 -69
- data/lib/game_machine/data_store.rb +111 -15
- data/lib/game_machine/data_stores/couchbase.rb +8 -3
- data/lib/game_machine/data_stores/gamecloud.rb +93 -0
- data/lib/game_machine/data_stores/jdbc.rb +98 -0
- data/lib/game_machine/default_handlers.rb +2 -0
- data/lib/game_machine/default_handlers/team_handler.rb +51 -0
- data/lib/game_machine/default_handlers/zone_manager.rb +30 -0
- data/lib/game_machine/endpoints.rb +0 -4
- data/lib/game_machine/endpoints/udp_incoming.rb +13 -5
- data/lib/game_machine/endpoints/udp_outgoing.rb +15 -9
- data/lib/game_machine/game_systems.rb +0 -2
- data/lib/game_machine/game_systems/agents/controller.rb +2 -2
- data/lib/game_machine/game_systems/entity_tracking.rb +0 -3
- data/lib/game_machine/game_systems/region_manager.rb +3 -2
- data/lib/game_machine/game_systems/region_service.rb +2 -2
- data/lib/game_machine/game_systems/remote_echo.rb +10 -0
- data/lib/game_machine/game_systems/team_manager.rb +2 -11
- data/lib/game_machine/grid.rb +5 -18
- data/lib/game_machine/handlers/authentication.rb +1 -9
- data/lib/game_machine/handlers/game.rb +27 -2
- data/lib/game_machine/handlers/player_authentication.rb +87 -0
- data/lib/game_machine/handlers/request.rb +9 -11
- data/lib/game_machine/hocon_config.rb +81 -0
- data/lib/game_machine/java_lib.rb +14 -1
- data/lib/game_machine/logger.rb +10 -23
- data/lib/game_machine/models.rb +1 -0
- data/lib/game_machine/mono_server.rb +6 -1
- data/lib/game_machine/object_db.rb +12 -6
- data/lib/game_machine/protobuf.rb +1 -1
- data/lib/game_machine/protobuf/game_messages.rb +13 -3
- data/lib/game_machine/protobuf/generate.rb +107 -5
- data/lib/game_machine/restart_watcher.rb +1 -1
- data/lib/game_machine/routes.rb +23 -0
- data/lib/game_machine/scheduler.rb +1 -1
- data/lib/game_machine/securerandom.rb +2 -0
- data/lib/game_machine/system_stats.rb +28 -7
- data/lib/game_machine/version.rb +1 -1
- data/lib/game_machine/wavefront_ext.rb +47 -0
- data/lib/game_machine/write_behind_cache.rb +24 -9
- data/mono/server/Makefile +1 -1
- data/mono/server/Newtonsoft.Json.dll +0 -0
- data/mono/server/build.bat +1 -1
- data/mono/server/callable.cs +9 -0
- data/mono/server/echo.cs +17 -0
- data/mono/server/message_router.cs +16 -23
- data/mono/server/messages.cs +1792 -417
- data/mono/server/protobuf-net.dll +0 -0
- data/mono/server/server.cs +120 -0
- data/mono/server/server.exe +0 -0
- data/pathfinding/astar.cpp +149 -0
- data/pathfinding/build.sh +6 -0
- data/pathfinding/build.txt +16 -0
- data/pathfinding/crowd.cpp +194 -0
- data/pathfinding/include/astar.h +49 -0
- data/pathfinding/include/common.h +5 -0
- data/pathfinding/include/crowd.h +43 -0
- data/pathfinding/include/micropather.h +511 -0
- data/pathfinding/include/navmesh.h +114 -0
- data/pathfinding/include/pathfinder.h +24 -0
- data/pathfinding/main.cpp +108 -17
- data/pathfinding/micropather.cpp +1062 -0
- data/pathfinding/navmesh.cpp +408 -0
- data/pathfinding/overrides/DetourCrowd.cpp +1446 -0
- data/pathfinding/overrides/DetourNavMeshQuery.cpp +3551 -0
- data/pathfinding/overrides/DetourNavMeshQuery.h +538 -0
- data/pathfinding/pathfinder.cpp +117 -0
- data/pathfinding/{bin → premake}/premake4 +0 -0
- data/pathfinding/premake/premake4.exe +0 -0
- data/pathfinding/premake4.lua +12 -3
- data/spec/actor/actor_spec.rb +0 -7
- data/spec/client_manager_spec.rb +1 -1
- data/spec/couchproxy_spec.rb +38 -0
- data/spec/entity_persistence_spec.rb +129 -0
- data/spec/game_systems/team_manager_spec.rb +2 -2
- data/spec/hashring_spec.rb +17 -39
- data/spec/java_grid_spec.rb +0 -2
- data/spec/misc_spec.rb +111 -0
- data/spec/mono_spec.rb +50 -3
- data/spec/reliable_message_spec.rb +38 -0
- data/spec/spec_helper.rb +4 -4
- data/spec/spec_helper_minimal.rb +10 -0
- data/web/app.rb +108 -86
- data/web/config/trinidad.yml +1 -0
- data/web/views/add_player.erb +25 -0
- data/web/views/index.erb +0 -0
- data/web/views/layout.erb +48 -0
- data/web/views/login.erb +25 -0
- data/web/views/players.erb +24 -0
- metadata +209 -94
- data/config/config.example.yml +0 -100
- data/config/regions.example.yml +0 -9
- data/games/example/lib/authentication_handler.rb +0 -69
- data/games/models.rb +0 -3
- data/games/models/clan_member.rb +0 -8
- data/games/models/clan_profile.rb +0 -9
- data/games/models/player.rb +0 -7
- data/games/plugins.rb +0 -1
- data/games/plugins/team_handler.rb +0 -49
- data/games/preload.rb +0 -13
- data/java/.gitignore +0 -1
- data/java/build.gradle +0 -95
- data/java/component.erb +0 -396
- data/java/gradle/wrapper/gradle-wrapper.jar +0 -0
- data/java/src/main/java/com/game_machine/core/GameMachineLoader.java +0 -25
- data/java/src/main/java/com/game_machine/core/Grid.java +0 -195
- data/java/src/main/resources/logback.xml +0 -14
- data/java/src/main/resources/logging.properties +0 -3
- data/lib/game_machine/actor/mono_actor.rb +0 -89
- data/lib/game_machine/auth_handlers/base.rb +0 -21
- data/lib/game_machine/auth_handlers/public.rb +0 -34
- data/lib/game_machine/endpoints/mono_gateway.rb +0 -87
- data/lib/game_machine/endpoints/tcp.rb +0 -51
- data/lib/game_machine/endpoints/tcp_handler.rb +0 -75
- data/lib/game_machine/endpoints/udp.rb +0 -88
- data/lib/game_machine/game_loader.rb +0 -46
- data/lib/game_machine/game_systems/region_settings.rb +0 -13
- data/lib/game_machine/hashring.rb +0 -48
- data/lib/game_machine/settings.rb +0 -11
- data/mono/server/actor.cs +0 -37
- data/mono/server/iactor.cs +0 -11
- data/mono/server/message_util.cs +0 -29
- data/mono/server/proxy_client.cs +0 -73
- data/mono/server/proxy_server.cs +0 -30
- data/mono/server/test_actor.cs +0 -33
- data/pathfinding/include/pathfind.h +0 -167
- data/pathfinding/pathfind.cpp +0 -174
- data/pathfinding/pathfinder.cs +0 -66
- data/script/server.sh +0 -109
- data/script/watch.sh +0 -11
- data/spec/commands/navigation_commands_spec.rb +0 -51
- data/spec/game_systems/entity_tracking_spec.rb +0 -64
- data/spec/navigation/detour_navmesh_spec.rb +0 -34
- data/spec/navigation/detour_path_spec.rb +0 -25
- data/spec/udp_server_spec.rb +0 -10
- data/web/controllers/auth_controller.rb +0 -19
- data/web/controllers/base_controller.rb +0 -16
- data/web/controllers/index_controller.rb +0 -7
- data/web/controllers/log_controller.rb +0 -47
- data/web/controllers/messages_controller.rb +0 -59
- data/web/controllers/player_register_controller.rb +0 -15
- data/web/views/game_messages.haml +0 -45
- data/web/views/index.haml +0 -6
- data/web/views/layout.haml +0 -41
- data/web/views/logs.haml +0 -32
- data/web/views/player_register.haml +0 -22
- data/web/views/player_registered.haml +0 -2
- data/web/views/register_layout.haml +0 -22
- data/web/views/restart.haml +0 -35
|
@@ -2,37 +2,35 @@ package com.game_machine.core;
|
|
|
2
2
|
|
|
3
3
|
import io.netty.buffer.ByteBuf;
|
|
4
4
|
import io.netty.buffer.Unpooled;
|
|
5
|
-
import io.netty.channel.ChannelFuture;
|
|
6
|
-
import io.netty.channel.ChannelFutureListener;
|
|
7
5
|
import io.netty.channel.ChannelHandlerContext;
|
|
8
6
|
import io.netty.channel.SimpleChannelInboundHandler;
|
|
9
7
|
import io.netty.channel.socket.DatagramPacket;
|
|
10
8
|
|
|
11
9
|
import java.net.InetSocketAddress;
|
|
12
10
|
import java.util.HashMap;
|
|
11
|
+
import java.util.concurrent.atomic.AtomicInteger;
|
|
13
12
|
|
|
14
13
|
import org.slf4j.Logger;
|
|
15
14
|
import org.slf4j.LoggerFactory;
|
|
16
15
|
|
|
16
|
+
import GameMachine.Messages.ClientMessage;
|
|
17
17
|
import akka.actor.ActorSelection;
|
|
18
18
|
|
|
19
|
-
import com.game_machine.core.ActorUtil;
|
|
20
|
-
import com.game_machine.core.NetMessage;
|
|
21
|
-
|
|
22
19
|
//@Sharable
|
|
23
20
|
public final class UdpServerHandler extends
|
|
24
21
|
SimpleChannelInboundHandler<DatagramPacket> {
|
|
25
22
|
|
|
23
|
+
public static AtomicInteger countIn = new AtomicInteger();
|
|
24
|
+
public static AtomicInteger countOut = new AtomicInteger();
|
|
25
|
+
|
|
26
26
|
private static final Logger log = LoggerFactory
|
|
27
27
|
.getLogger(UdpServerHandler.class);
|
|
28
28
|
public ChannelHandlerContext ctx = null;
|
|
29
29
|
private ActorSelection inbound;
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
|
|
33
32
|
public UdpServerHandler() {
|
|
34
|
-
this.inbound = ActorUtil
|
|
35
|
-
.getSelectionByName("GameMachine::Endpoints::UdpIncoming");
|
|
33
|
+
this.inbound = ActorUtil.getSelectionByName("message_gateway");
|
|
36
34
|
}
|
|
37
35
|
|
|
38
36
|
@Override
|
|
@@ -53,37 +51,36 @@ public final class UdpServerHandler extends
|
|
|
53
51
|
this.ctx = ctx;
|
|
54
52
|
}
|
|
55
53
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
//log.info("send " + "host: " + host + " port: " + port + " bytes: "
|
|
59
|
-
// + bytes.toString()+" ctx: "+ctx);
|
|
54
|
+
|
|
55
|
+
public void send(InetSocketAddress address, byte[] bytes, ChannelHandlerContext ctx) {
|
|
60
56
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
57
|
+
ByteBuf buf = Unpooled.wrappedBuffer(bytes);
|
|
58
|
+
DatagramPacket packet = new DatagramPacket(buf, address);
|
|
59
|
+
ctx.writeAndFlush(packet);
|
|
60
|
+
countOut.incrementAndGet();
|
|
65
61
|
}
|
|
66
62
|
|
|
67
|
-
public void echo(ChannelHandlerContext ctx, DatagramPacket m, byte[] bytes)
|
|
68
|
-
{
|
|
63
|
+
public void echo(ChannelHandlerContext ctx, DatagramPacket m, byte[] bytes) {
|
|
69
64
|
ByteBuf buf = Unpooled.copiedBuffer(bytes);
|
|
70
|
-
DatagramPacket packet = new DatagramPacket(buf,
|
|
71
|
-
|
|
65
|
+
DatagramPacket packet = new DatagramPacket(buf, new InetSocketAddress(m
|
|
66
|
+
.sender().getHostString(), m.sender().getPort()));
|
|
72
67
|
ctx.writeAndFlush(packet);
|
|
73
68
|
}
|
|
74
|
-
|
|
69
|
+
|
|
75
70
|
@Override
|
|
76
71
|
protected void channelRead0(ChannelHandlerContext ctx, DatagramPacket m)
|
|
77
72
|
throws Exception {
|
|
78
73
|
byte[] bytes = new byte[m.content().readableBytes()];
|
|
79
74
|
m.content().readBytes(bytes);
|
|
80
75
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
76
|
+
NetMessage netMessage = new NetMessage(NetMessage.UDP, m.sender()
|
|
77
|
+
.getHostString(), m.sender().getPort(), ctx);
|
|
78
|
+
netMessage.bytes = bytes;
|
|
79
|
+
netMessage.address = m.sender();
|
|
84
80
|
log.debug("MessageReceived length" + bytes.length + " "
|
|
85
81
|
+ new String(bytes));
|
|
86
|
-
this.inbound.tell(
|
|
82
|
+
this.inbound.tell(netMessage, null);
|
|
83
|
+
countIn.incrementAndGet();
|
|
87
84
|
|
|
88
85
|
}
|
|
89
86
|
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
package com.game_machine.core;
|
|
2
|
+
|
|
3
|
+
public class Vector3 {
|
|
4
|
+
private double x;
|
|
5
|
+
private double y;
|
|
6
|
+
private double z;
|
|
7
|
+
|
|
8
|
+
public Vector3() {
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
public Vector3(double x, double y, double z) {
|
|
12
|
+
this.x = x;
|
|
13
|
+
this.y = y;
|
|
14
|
+
this.z = z;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
public static Vector3 from(Vector3 other) {
|
|
18
|
+
Vector3 vec = new Vector3(other.x,other.y,other.z);
|
|
19
|
+
return vec;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
public Vector3(Vector3 other) {
|
|
23
|
+
x = other.x;
|
|
24
|
+
y = other.y;
|
|
25
|
+
z = other.z;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public double x() {
|
|
29
|
+
return x;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
public double y() {
|
|
33
|
+
return y;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
public double z() {
|
|
37
|
+
return z;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
public void set(double x, double y, double z) {
|
|
41
|
+
this.x = x;
|
|
42
|
+
this.y = y;
|
|
43
|
+
this.z = z;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
public void set(Vector3 other) {
|
|
47
|
+
x = other.x;
|
|
48
|
+
y = other.y;
|
|
49
|
+
z = other.z;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
public void addLocal(Vector3 other) {
|
|
53
|
+
x += other.x;
|
|
54
|
+
y += other.y;
|
|
55
|
+
z += other.z;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
public void addLocal(double x, double y, double z) {
|
|
59
|
+
this.x += x;
|
|
60
|
+
this.y += y;
|
|
61
|
+
this.z += z;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
public Vector3 subtract(Vector3 other) {
|
|
65
|
+
return new Vector3(x - other.x, y - other.y, z - other.z);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
public double angle(Vector3 other) {
|
|
69
|
+
// TODO: Find a faster arccos and sqrt method
|
|
70
|
+
|
|
71
|
+
double lengthSquare = x * x + y * y + z * z;
|
|
72
|
+
double otherLengthSquare = other.x * other.x + other.y * other.y + other.z * other.z;
|
|
73
|
+
|
|
74
|
+
double angle = Math.acos((x * other.x + y * other.y + z * other.z)/Math.sqrt(lengthSquare * otherLengthSquare));
|
|
75
|
+
|
|
76
|
+
return angle;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
public Vector3 cross(Vector3 other) {
|
|
80
|
+
return new Vector3(y * other.z - z * other.y,
|
|
81
|
+
z * other.x - x * other.z, x * other.y - y * other.x);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
public double dot(Vector3 other) {
|
|
85
|
+
return (x * other.x + y * other.y + z * other.z);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
public void crossLocal(Vector3 other) {
|
|
89
|
+
set(y * other.z - z * other.y, z * other.x - x * other.z, x * other.y - y * other.x);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
public Vector3 multiply(double scalar) {
|
|
93
|
+
return new Vector3(x * scalar, y * scalar, z * scalar);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
public void multiplyLocal(double scalar) {
|
|
97
|
+
x = scalar * x;
|
|
98
|
+
y = scalar * y;
|
|
99
|
+
z = scalar * z;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
public Vector3 normalize() {
|
|
103
|
+
double length = Math.sqrt(x * x + y * y + z * z);
|
|
104
|
+
if (length > Double.MIN_NORMAL) {
|
|
105
|
+
return new Vector3(x / length, y / length, z / length);
|
|
106
|
+
} else {
|
|
107
|
+
return new Vector3(0, 0, 0);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
public void normalizeLocal() {
|
|
112
|
+
double length = Math.sqrt(x * x + y * y + z * z);
|
|
113
|
+
if (length > Double.MIN_NORMAL) {
|
|
114
|
+
x /= length;
|
|
115
|
+
y /= length;
|
|
116
|
+
z /= length;
|
|
117
|
+
} else {
|
|
118
|
+
x = y = z = 0;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Obtain distance between position vectors
|
|
123
|
+
public double distance(Vector3 other) {
|
|
124
|
+
return Math.sqrt(Math.pow(x - other.x, 2) + Math.pow(y - other.y, 2) + Math.pow(z - other.z, 2));
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// Project the vector onto the plane passing through the origin, perpendicular to the given normal
|
|
128
|
+
public Vector3 projectNormal(Vector3 normal) {
|
|
129
|
+
return subtract(normal.multiply(this.dot(normal)));
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
public Vector3 rotate(Vector3 normal, double angle) {
|
|
133
|
+
// Parametric equation for circle in 3D space:
|
|
134
|
+
// P = Rcos(t)u + Rsin(t)nxu + c
|
|
135
|
+
//
|
|
136
|
+
// Where:
|
|
137
|
+
// -u is a unit vector from the centre of the circle to any point
|
|
138
|
+
// on the circumference
|
|
139
|
+
// -R is the radius
|
|
140
|
+
// -n is a unit vector perpendicular to the plane
|
|
141
|
+
// -c is the centre of the circle.
|
|
142
|
+
|
|
143
|
+
//TODO: obtain a more efficient sin function
|
|
144
|
+
|
|
145
|
+
Vector3 rotated;
|
|
146
|
+
|
|
147
|
+
rotated = normal.normalize();
|
|
148
|
+
rotated.crossLocal(this);
|
|
149
|
+
rotated.multiplyLocal(Math.sin(angle));
|
|
150
|
+
rotated.addLocal(this.multiply(Math.cos(angle)));
|
|
151
|
+
|
|
152
|
+
return rotated;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
@Override
|
|
156
|
+
public String toString() {
|
|
157
|
+
return "(" + x + ", " + y + ", " + z + ")";
|
|
158
|
+
}
|
|
159
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
package com.game_machine.orm.models;
|
|
2
|
+
|
|
3
|
+
import org.javalite.activejdbc.DB;
|
|
4
|
+
import org.javalite.activejdbc.Model;
|
|
5
|
+
import org.javalite.activejdbc.annotations.IdName;
|
|
6
|
+
|
|
7
|
+
import com.game_machine.core.DbConnectionPool;
|
|
8
|
+
import com.zaxxer.hikari.HikariDataSource;
|
|
9
|
+
|
|
10
|
+
/*
|
|
11
|
+
Postgresql
|
|
12
|
+
|
|
13
|
+
Database/user creation
|
|
14
|
+
CREATE ROLE gamemachine WITH ENCRYPTED PASSWORD 'gamemachine' LOGIN CREATEDB CREATEROLE;
|
|
15
|
+
CREATE DATABASE gamemachine WITH OWNER=gamemachine ENCODING='UTF8';
|
|
16
|
+
|
|
17
|
+
Table
|
|
18
|
+
CREATE TABLE player_items (
|
|
19
|
+
id bigserial NOT NULL,
|
|
20
|
+
|
|
21
|
+
player_item_id character varying(128) NOT NULL,
|
|
22
|
+
|
|
23
|
+
player_item_name character varying(128) NOT NULL,
|
|
24
|
+
|
|
25
|
+
player_item_quantity integer NOT NULL,
|
|
26
|
+
|
|
27
|
+
player_item_color character varying(128) DEFAULT NULL,
|
|
28
|
+
|
|
29
|
+
weapon_attack integer DEFAULT NULL,
|
|
30
|
+
|
|
31
|
+
weapon_delay integer DEFAULT NULL,
|
|
32
|
+
|
|
33
|
+
consumable_type character varying(128) DEFAULT NULL,
|
|
34
|
+
|
|
35
|
+
consumable_size character varying(128) DEFAULT NULL,
|
|
36
|
+
|
|
37
|
+
cost_amount double precision DEFAULT NULL,
|
|
38
|
+
|
|
39
|
+
cost_currency character varying(128) DEFAULT NULL,
|
|
40
|
+
|
|
41
|
+
player_id character varying(128) NOT NULL,
|
|
42
|
+
CONSTRAINT player_item_pkey PRIMARY KEY (id),
|
|
43
|
+
CONSTRAINT player_item_id_player_id_idx UNIQUE (player_item_id,player_id)
|
|
44
|
+
);
|
|
45
|
+
alter table player_items owner to gamemachine;
|
|
46
|
+
|
|
47
|
+
Mysql
|
|
48
|
+
|
|
49
|
+
Database/user creation
|
|
50
|
+
CREATE DATABASE IF NOT EXISTS gamemachine CHARACTER SET utf8 COLLATE utf8_general_ci;
|
|
51
|
+
GRANT ALL PRIVILEGES ON gamemachine.* TO 'gamemachine'@'%' IDENTIFIED BY 'gamemachine' WITH GRANT OPTION;
|
|
52
|
+
FLUSH PRIVILEGES;
|
|
53
|
+
|
|
54
|
+
Table
|
|
55
|
+
CREATE TABLE `player_items` (
|
|
56
|
+
`id` int(11) NOT NULL AUTO_INCREMENT,
|
|
57
|
+
|
|
58
|
+
`player_item_id` varchar(128) NOT NULL,
|
|
59
|
+
|
|
60
|
+
`player_item_name` varchar(128) NOT NULL,
|
|
61
|
+
|
|
62
|
+
`player_item_quantity` int(11) NOT NULL,
|
|
63
|
+
|
|
64
|
+
`player_item_color` varchar(128) DEFAULT NULL,
|
|
65
|
+
|
|
66
|
+
`weapon_attack` int(11) DEFAULT NULL,
|
|
67
|
+
|
|
68
|
+
`weapon_delay` int(11) DEFAULT NULL,
|
|
69
|
+
|
|
70
|
+
`consumable_type` varchar(128) DEFAULT NULL,
|
|
71
|
+
|
|
72
|
+
`consumable_size` varchar(128) DEFAULT NULL,
|
|
73
|
+
|
|
74
|
+
`cost_amount` float DEFAULT NULL,
|
|
75
|
+
|
|
76
|
+
`cost_currency` varchar(128) DEFAULT NULL,
|
|
77
|
+
|
|
78
|
+
`player_id` varchar(128) NOT NULL,
|
|
79
|
+
PRIMARY KEY(`id`),
|
|
80
|
+
UNIQUE KEY `player_item_id_player_id_idx` (`player_item_id`,`player_id`)
|
|
81
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
|
82
|
+
*/
|
|
83
|
+
|
|
84
|
+
public class PlayerItem extends Model {
|
|
85
|
+
|
|
86
|
+
public static void openTransaction() {
|
|
87
|
+
open();
|
|
88
|
+
DB db = new DB("default");
|
|
89
|
+
db.openTransaction();
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
public static void commitTransaction() {
|
|
93
|
+
DB db = new DB("default");
|
|
94
|
+
db.commitTransaction();
|
|
95
|
+
close();
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
public static void rollbackTransaction() {
|
|
99
|
+
DB db = new DB("default");
|
|
100
|
+
db.rollbackTransaction();
|
|
101
|
+
close();
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
public static void close() {
|
|
105
|
+
DB db = new DB("default");
|
|
106
|
+
if(db.hasConnection()) {
|
|
107
|
+
db.close();
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
public static void open() {
|
|
112
|
+
DB db = new DB("default");
|
|
113
|
+
if(!db.hasConnection()) {
|
|
114
|
+
HikariDataSource ds = DbConnectionPool.getInstance().getDataSource("game_machine_orm");
|
|
115
|
+
db.open(ds);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
package com.game_machine.orm.models;
|
|
2
|
+
|
|
3
|
+
import org.javalite.activejdbc.DB;
|
|
4
|
+
import org.javalite.activejdbc.Model;
|
|
5
|
+
import org.javalite.activejdbc.annotations.IdName;
|
|
6
|
+
|
|
7
|
+
import com.game_machine.core.DbConnectionPool;
|
|
8
|
+
import com.zaxxer.hikari.HikariDataSource;
|
|
9
|
+
|
|
10
|
+
/*
|
|
11
|
+
Postgresql
|
|
12
|
+
|
|
13
|
+
Database/user creation
|
|
14
|
+
CREATE ROLE gamemachine WITH ENCRYPTED PASSWORD 'gamemachine' LOGIN CREATEDB CREATEROLE;
|
|
15
|
+
CREATE DATABASE gamemachine WITH OWNER=gamemachine ENCODING='UTF8';
|
|
16
|
+
|
|
17
|
+
Table
|
|
18
|
+
CREATE TABLE test_objects (
|
|
19
|
+
id bigserial NOT NULL,
|
|
20
|
+
|
|
21
|
+
test_object_optional_string character varying(128) DEFAULT NULL,
|
|
22
|
+
|
|
23
|
+
test_object_required_string character varying(128) NOT NULL,
|
|
24
|
+
|
|
25
|
+
test_object_numbers integer DEFAULT NULL,
|
|
26
|
+
|
|
27
|
+
test_object_bvalue integer DEFAULT NULL,
|
|
28
|
+
|
|
29
|
+
test_object_dvalue double precision DEFAULT NULL,
|
|
30
|
+
|
|
31
|
+
test_object_fvalue double precision DEFAULT NULL,
|
|
32
|
+
|
|
33
|
+
test_object_numbers64 integer DEFAULT NULL,
|
|
34
|
+
|
|
35
|
+
test_object_id character varying(128) NOT NULL,
|
|
36
|
+
|
|
37
|
+
player_id character varying(128) NOT NULL,
|
|
38
|
+
CONSTRAINT test_object_pkey PRIMARY KEY (id),
|
|
39
|
+
CONSTRAINT test_object_id_player_id_idx UNIQUE (test_object_id,player_id)
|
|
40
|
+
);
|
|
41
|
+
alter table test_objects owner to gamemachine;
|
|
42
|
+
|
|
43
|
+
Mysql
|
|
44
|
+
|
|
45
|
+
Database/user creation
|
|
46
|
+
CREATE DATABASE IF NOT EXISTS gamemachine CHARACTER SET utf8 COLLATE utf8_general_ci;
|
|
47
|
+
GRANT ALL PRIVILEGES ON gamemachine.* TO 'gamemachine'@'%' IDENTIFIED BY 'gamemachine' WITH GRANT OPTION;
|
|
48
|
+
FLUSH PRIVILEGES;
|
|
49
|
+
|
|
50
|
+
Table
|
|
51
|
+
CREATE TABLE `test_objects` (
|
|
52
|
+
`id` int(11) NOT NULL AUTO_INCREMENT,
|
|
53
|
+
|
|
54
|
+
`test_object_optional_string` varchar(128) DEFAULT NULL,
|
|
55
|
+
|
|
56
|
+
`test_object_required_string` varchar(128) NOT NULL,
|
|
57
|
+
|
|
58
|
+
`test_object_numbers` int(11) DEFAULT NULL,
|
|
59
|
+
|
|
60
|
+
`test_object_bvalue` tinyint(4) DEFAULT NULL,
|
|
61
|
+
|
|
62
|
+
`test_object_dvalue` double DEFAULT NULL,
|
|
63
|
+
|
|
64
|
+
`test_object_fvalue` float DEFAULT NULL,
|
|
65
|
+
|
|
66
|
+
`test_object_numbers64` int(11) DEFAULT NULL,
|
|
67
|
+
|
|
68
|
+
`test_object_id` varchar(128) NOT NULL,
|
|
69
|
+
|
|
70
|
+
`player_id` varchar(128) NOT NULL,
|
|
71
|
+
PRIMARY KEY(`id`),
|
|
72
|
+
UNIQUE KEY `test_object_id_player_id_idx` (`test_object_id`,`player_id`)
|
|
73
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
|
74
|
+
*/
|
|
75
|
+
|
|
76
|
+
public class TestObject extends Model {
|
|
77
|
+
|
|
78
|
+
public static void openTransaction() {
|
|
79
|
+
open();
|
|
80
|
+
DB db = new DB("default");
|
|
81
|
+
db.openTransaction();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
public static void commitTransaction() {
|
|
85
|
+
DB db = new DB("default");
|
|
86
|
+
db.commitTransaction();
|
|
87
|
+
close();
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
public static void rollbackTransaction() {
|
|
91
|
+
DB db = new DB("default");
|
|
92
|
+
db.rollbackTransaction();
|
|
93
|
+
close();
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
public static void close() {
|
|
97
|
+
DB db = new DB("default");
|
|
98
|
+
if(db.hasConnection()) {
|
|
99
|
+
db.close();
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
public static void open() {
|
|
104
|
+
DB db = new DB("default");
|
|
105
|
+
if(!db.hasConnection()) {
|
|
106
|
+
HikariDataSource ds = DbConnectionPool.getInstance().getDataSource("game_machine_orm");
|
|
107
|
+
db.open(ds);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|