Skip to content

Commit

Permalink
Reduce how much time passes—a kilocycle is way too long
Browse files Browse the repository at this point in the history
  • Loading branch information
jspahrsummers committed Jul 24, 2024
1 parent 282fbf8 commit 5759d61
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 35 deletions.
5 changes: 4 additions & 1 deletion actors/player.gd
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ var _rigid_body_turner: RigidBodyTurner
## When using the "absolute" control scheme, this is the tolerance (in radians) for being slightly off-rotated while enabling thrusters.
const ABSOLUTE_DIRECTION_TOLERANCE_RAD = 0.1745

## The approximate number of days that should pass with each planetary landing.
const PLANET_LANDING_APPROXIMATE_DAYS = 1

# TODO: Put this somewhere better (per ship?)
const HYPERSPACE_ARRIVAL_RADIUS = 8.0
const MAX_LANDING_DISTANCE = 2.0
Expand Down Expand Up @@ -230,7 +233,7 @@ func _land() -> void:
self._depart_from_planet())

func _depart_from_planet() -> void:
self.calendar.increment_kilocycle()
self.calendar.pass_approximate_days(PLANET_LANDING_APPROXIMATE_DAYS)
self._reset_controls()
self._reset_velocity()
self.takeoff_sound.play()
Expand Down
5 changes: 4 additions & 1 deletion mechanics/hyperspace/hyperspace_scene_switcher.gd
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ class_name HyperspaceSceneSwitcher
## The game [Calendar] to update when jumping, to represent time passing.
@export var calendar: Calendar

## The approximate number of days that should pass with each hyperspace jump.
const HYPERSPACE_APPROXIMATE_TRAVEL_DAYS = 3

## Fires when the hyperspace destination has been loaded and added to the current scene, but before the full visual effect has finished.
signal jump_destination_loaded(new_system_instance: StarSystemInstance)

Expand Down Expand Up @@ -58,7 +61,7 @@ func load_jump_destination() -> void:
star_system_instance.add_child(player_ship)
self.add_child(star_system_instance)

calendar.increment_kilocycle()
calendar.pass_approximate_days(HYPERSPACE_APPROXIMATE_TRAVEL_DAYS)

self.hyperdrive_system.jump_destination = null
self.jump_destination_loaded.emit(star_system_instance)
Expand Down
57 changes: 25 additions & 32 deletions mechanics/time/calendar.gd
Original file line number Diff line number Diff line change
Expand Up @@ -24,50 +24,43 @@ const ROTATIONS_PER_CYCLE = 2686610
## The year (CE) that GST timekeeping began.
const TIMEKEEPING_STARTING_YEAR = 2050

## When [method increment_kilocycle] is called, the current cycle ([member get_current_cycle]) is reset, then offset by a random amount up to this bound.
##
## This is used to give players more interesting timestamps, instead of the cycle always starting at 0.
const MAX_RANDOM_CYCLE_OFFSET = 900
## The maximum random variance in cycles to add or subtract when time passes.
const TIME_PASSING_RANDOMNESS = 0.1

## The current (integral) kilocycle in game.
@export var current_kilocycle: int = 214: # ~4830 CE
## The in-game cycle in GST, [i]without[/i] accounting for how many ticks have passed in the game engine.
var _base_cycle: float:
set(value):
if value == current_kilocycle:
if value == _base_cycle:
return

current_kilocycle = value
_base_cycle = value
self.emit_changed()

## The millisecond tick when the current kilocycle started, used to calculate the current (sub-kilocycle) cycle.
var _current_kilocycle_start_ticks_msec: int

## The random offset to add to the current cycle, to make timestamps more interesting.
##
## See [constant MAX_RANDOM_CYCLE_OFFSET]
var _current_cycle_offset: float
## The millisecond tick when the calendar started timekeeping.
var _calendar_start_ticks_msec: int

func _init() -> void:
self._reset_cycle()
self._calendar_start_ticks_msec = Time.get_ticks_msec()
self._base_cycle = 214000 + randf_range(0, 999) # ~4830 CE

func _reset_cycle() -> void:
self._current_kilocycle_start_ticks_msec = Time.get_ticks_msec()
self._current_cycle_offset = randf_range(0, MAX_RANDOM_CYCLE_OFFSET)
## Advances the in-game clock by approximately the given number of [param days] (converted to GST).
func pass_approximate_days(days: float) -> void:
var cycles_to_pass := days * 24 * randf_range(1 - TIME_PASSING_RANDOMNESS, 1 + TIME_PASSING_RANDOMNESS)
self._base_cycle += cycles_to_pass

## Move forward the kilocycle counter by the given [param delta].
##
## Also resets the current cycle count [i]within[/i] the kilocycle.
func increment_kilocycle(delta: int=1) -> void:
# Reset cycle first, since changing the current kilocycle will fire the changed signal.
self._reset_cycle()
self.current_kilocycle += delta

## Returns the number of cycles that have passed [i]within[/i] the current kilocycle.
## Returns the current in-game cycle in GST, including accounting for actual (wall-clock) time that has passed in the game engine.
func get_current_cycle() -> float:
var msec_passed := Time.get_ticks_msec() - self._current_kilocycle_start_ticks_msec
var msec_passed := Time.get_ticks_msec() - self._calendar_start_ticks_msec
var rotations := msec_passed / PULSAR_ROTATION_PERIOD_MSEC
var cycles := rotations / ROTATIONS_PER_CYCLE
return cycles + self._current_cycle_offset
var cycle_offset := rotations / ROTATIONS_PER_CYCLE
return self._base_cycle + cycle_offset

## Formats the current GST timestamp as a string, suitable for presentation.
func get_gst() -> String:
return "%d.%03.3f GST" % [self.current_kilocycle, self.get_current_cycle()]
var current_cycle := self.get_current_cycle()

var kilocycles := int(current_cycle / 1000)
var cycles := int(current_cycle) % 1000
var millicycles := int((current_cycle - floorf(current_cycle)) * 1000)

return "%03d.%03d.%03d GST" % [kilocycles, cycles, millicycles]
1 change: 0 additions & 1 deletion screens/game/game.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@

[sub_resource type="Resource" id="Resource_jc1pg"]
script = ExtResource("46_cos1s")
current_kilocycle = 214

[sub_resource type="Resource" id="Resource_rwdpp"]
resource_local_to_scene = true
Expand Down

0 comments on commit 5759d61

Please sign in to comment.