hestia-rsps / hestia

An open-source Kotlin game server.
BSD 3-Clause "New" or "Revised" License
16 stars 4 forks source link

Option binding #139

Closed GregHib closed 4 years ago

GregHib commented 4 years ago

Description

The existing on event listening has a O(N) lookup complexity, where N is the total number of listeners in use.

This is fine for the majority of event's which will have very few listeners, however the most commonly used listeners might see performance hits as content grows.

Fortunantley a lot of content has fixed preconditions for execution, allowing conditions to be hashed and stored in a map for N(1) lookup.

Proposal

Initially thought that due to the limited number of Option Types that applied, they could all be stored in a single location Map<Type, Map<String, Map<Long, () -> Unit>>>. However it's not apparent that using having a String Option and Hash separate is necessary for all Types and so they should be done on an individual basis.

Both option and id can be represented by one of three ways:

But a conditional can be obtained many different ways depending on type:

Types

Scenarios

Examples

npc(option = "Talk-to", "Man", "Woman") {
}
npc(option = "Attack", 2, 3, 175) {
}
obj(option = "Open", contains = "door") {
}
player(option = "Challenge") {
}
on(Option.name("Close"), By.objectName("Door", "Wooden Door")) {
}
on("Use", By.itemId(995) on By.itemId(995)) {
}
on(interface(Inventory, "Drop"), By.id(995)) {
}
on(ConditionalBuilder()
    .withNpcName("Bob", "Doris")
    .withOption(2)
) {
}

Questions

How will data be passed if not via EntityAction? E.g "Talk-to" "Hans" would need index of interacted npc.

GregHib commented 4 years ago

Basic binding done, interface "on..". bindings not worth doing for now.