Class: RuneRb::Game::World::Instance

Inherits:
Object
  • Object
show all
Includes:
Gateway, Pipeline, Setup, Synchronization, System::Log
Defined in:
app/game/world/instance.rb

Overview

A World Instance object models a virtual game world. The Instance object manages mobs, events, and most of all the game logic processing.

Since:

  • 0.9.3

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Synchronization

#start_sync_service

Methods included from Pipeline

#post, #start_pipeline

Methods included from Gateway

#receive, #release

Methods included from System::Log

#class_name, #err, #err!, #log, #log!, #symbolize_file

Constructor Details

#initialize(config) ⇒ Instance

Called when a new World Instance is created

Since:

  • 0.9.3


23
24
25
26
# File 'app/game/world/instance.rb', line 23

def initialize(config)
  setup(config)
  log 'New World Instance initialized!'
end

Instance Attribute Details

#entitiesHash (readonly)

Returns a map of entities the Instance has spawned.

Returns:

  • (Hash)

    a map of entities the Instance has spawned

Since:

  • 0.9.3


14
15
16
# File 'app/game/world/instance.rb', line 14

def entities
  @entities
end

#idInteger (readonly)

Returns the id of the world instance.

Returns:

  • (Integer)

    the id of the world instance

Since:

  • 0.9.3


17
18
19
# File 'app/game/world/instance.rb', line 17

def id
  @id
end

#settingsHash (readonly)

Returns a map of settings for the World instance.

Returns:

  • (Hash)

    a map of settings for the World instance.

Since:

  • 0.9.3


20
21
22
# File 'app/game/world/instance.rb', line 20

def settings
  @settings
end

Instance Method Details

#inspectObject

Since:

  • 0.9.3


28
29
30
# File 'app/game/world/instance.rb', line 28

def inspect
  "#{RuneRb::GLOBAL[:COLOR].green("[Title]: #{RuneRb::GLOBAL[:COLOR].yellow.bold(@settings[:LABEL])}")}\n#{RuneRb::GLOBAL[:COLOR].green("[Players]: #{RuneRb::GLOBAL[:COLOR].yellow.bold(@entities[:players].size)}/#{@settings[:MAX_PLAYERS]}]")}\n#{RuneRb::GLOBAL[:COLOR].green("[Mobs]: #{RuneRb::GLOBAL[:COLOR].yellow.bold(@entities[:mobs].size)}/#{@settings[:MAX_MOBS]}]")}"
end

#shutdownObject

Shut down the world instance, releasing it's contexts.

Since:

  • 0.9.3


33
34
35
36
37
38
39
40
# File 'app/game/world/instance.rb', line 33

def shutdown
  # release all contexts
  @entities[:players].each_value { |context| release(context) }
  @status = :CLOSED
  # RuneRb::World::Instance.dump(self) if graceful
ensure
  log! "Total Instance Up-time: #{up_time.to_i.to_ftime}"
end

#up_timeObject

The current up-time for the server.

Since:

  • 0.9.3


43
44
45
# File 'app/game/world/instance.rb', line 43

def up_time
  (Process.clock_gettime(Process::CLOCK_MONOTONIC) - (@start[:time] || Time.now)).round(3)
end