Skip to content

Commit

Permalink
Merge pull request #387 from Mr-Auto/some-new-stuff
Browse files Browse the repository at this point in the history
Use Vec2 more, some small issues fix, more unknown stuff about camera and Hud
  • Loading branch information
Dregu authored Jul 30, 2024
2 parents 8e77955 + 39f77b7 commit dd300d1
Show file tree
Hide file tree
Showing 28 changed files with 358 additions and 178 deletions.
39 changes: 33 additions & 6 deletions docs/game_data/spel2.lua

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 33 additions & 6 deletions docs/src/includes/_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -498,11 +498,12 @@ int | [bombs](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=bombs) |
int | [ropes](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=ropes) |
bool | [ankh](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=ankh) |
bool | [kapala](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=kapala) |
int | [kapala_blood](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=kapala_blood) |
[SpritePosition](#SpritePosition) | [kapala_sprite](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=kapala_sprite) |
bool | [poison](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=poison) |
bool | [curse](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=curse) |
bool | [elixir](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=elixir) |
[ENT_TYPE](#ENT_TYPE) | [crown](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=crown) | [Powerup](#Powerup) type or 0
array<[SpritePosition](#SpritePosition), 18> | [powerup_sprites](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=powerup_sprites) |
int | [item_count](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=item_count) | Amount of generic pickup items at the bottom. Set to 0 to not draw them.

### Inventory
Expand Down Expand Up @@ -705,16 +706,38 @@ array<[HudInventory](#HudInventory), MAX_PLAYERS> | [inventory](https://gi
bool | [udjat](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=udjat) |
int | [money_total](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=money_total) |
int | [money_counter](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=money_counter) |
int | [time_total](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=time_total) |
int | [time_level](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=time_level) |
int | [time_total](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=time_total) | in ms
int | [time_level](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=time_level) | in ms
int | [world_num](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=world_num) |
int | [level_num](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=level_num) |
bool | [angry_shopkeeper](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=angry_shopkeeper) |
bool | [seed_shown](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=seed_shown) |
int | [seed](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=seed) |
float | [opacity](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=opacity) |
float | [roll_in](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=roll_in) |
array<[HudPlayer](#HudPlayer), MAX_PLAYERS> | [players](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=players) |
[HudMoney](#HudMoney) | [money](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=money) |
[ParticleEmitterInfo](#ParticleEmitterInfo) | [money_increase_sparkles](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=money_increase_sparkles) |
[HudElement](#HudElement) | [timer](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=timer) |
[HudElement](#HudElement) | [level](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=level) |
float | [clover_falling_apart_timer](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=clover_falling_apart_timer) |
array<[ParticleEmitterInfo](#ParticleEmitterInfo), MAX_PLAYERS> | [player_cursed_particles](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=player_cursed_particles) |
array<[ParticleEmitterInfo](#ParticleEmitterInfo), MAX_PLAYERS> | [player_poisoned_particles](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=player_poisoned_particles) |
[TextureRenderingInfo](#TextureRenderingInfo) | [player_highlight](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=player_highlight) | For player related icons, they use the same TextureRendering, just offset while drawing
[TextureRenderingInfo](#TextureRenderingInfo) | [player_heart](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=player_heart) |
[TextureRenderingInfo](#TextureRenderingInfo) | [player_ankh](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=player_ankh) |
[TextureRenderingInfo](#TextureRenderingInfo) | [kapala_icon](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=kapala_icon) |
[TextureRenderingInfo](#TextureRenderingInfo) | [player_crown](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=player_crown) |
[TextureRenderingInfo](#TextureRenderingInfo) | [player_bomb](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=player_bomb) |
[TextureRenderingInfo](#TextureRenderingInfo) | [player_rope](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=player_rope) |
[TextureRenderingInfo](#TextureRenderingInfo) | [udjat_icon](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=udjat_icon) |
[TextureRenderingInfo](#TextureRenderingInfo) | [money_and_time_highlight](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=money_and_time_highlight) | Money and time use the same TextureRendering, just offset while drawing
[TextureRenderingInfo](#TextureRenderingInfo) | [dollar_icon](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=dollar_icon) |
[TextureRenderingInfo](#TextureRenderingInfo) | [hourglass_icon](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=hourglass_icon) |
[TextureRenderingInfo](#TextureRenderingInfo) | [clover_icon](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=clover_icon) |
[TextureRenderingInfo](#TextureRenderingInfo) | [level_highlight](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=level_highlight) |
[TextureRenderingInfo](#TextureRenderingInfo) | [level_icon](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=level_icon) |
[TextureRenderingInfo](#TextureRenderingInfo) | [seed_background](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=seed_background) |

### HudElement

Expand Down Expand Up @@ -997,7 +1020,7 @@ Type | Name | Description
float | [x](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=x) |
float | [y](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=y) |

### SpearDanglerAnimFrames
### SpritePosition


Type | Name | Description
Expand Down Expand Up @@ -2489,7 +2512,7 @@ int | [menu_id](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=menu_id
int | [transfer_to_menu_id](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=transfer_to_menu_id) |
float | [menu_text_opacity](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=menu_text_opacity) |
array<float, 6> | [spear_position](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=spear_position) |
array<[SpearDanglerAnimFrames](#SpearDanglerAnimFrames), 6> | [spear_dangler](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=spear_dangler) |
array<[SpritePosition](#SpritePosition), 6> | [spear_dangler](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=spear_dangler) |
array<int, 6> | [spear_dangle_momentum](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=spear_dangle_momentum) |
array<int, 6> | [spear_dangle_angle](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=spear_dangle_angle) |
float | [play_scroll_descend_timer](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=play_scroll_descend_timer) |
Expand Down Expand Up @@ -2837,8 +2860,12 @@ float | [shake_amplitude](https://github.com/spelunky-fyi/overlunky/search?l=Lua
float | [shake_multiplier_x](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=shake_multiplier_x) |
float | [shake_multiplier_y](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=shake_multiplier_y) |
bool | [uniform_shake](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=uniform_shake) |
int | [focused_entity_uid](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=focused_entity_uid) |
int | [focused_entity_uid](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=focused_entity_uid) | if set to -1, you have free control over camera focus through focus_x, focus_y
float | [inertia](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=inertia) | This is a bad name, but it represents the camera tweening speed. [0..5] where 0=still, 1=default (move 20% of distance per frame), 5=max (move 5*20% or 100% aka instantly to destination per frame)
int | [peek_timer](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=peek_timer) | amount of frames to freeze camera in place and move to the peek_layer<br/>during the peek you can freely set camera position no matter if focused_entity_uid is set to -1 or not
int | [peek_layer](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=peek_layer) |
[AABB](#AABB) | [get_bounds()](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=get_bounds) |
nil | [set_bounds(AABB bounds)](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=set_bounds) |

### GameManager

Expand Down
4 changes: 2 additions & 2 deletions src/game_api/containers/custom_allocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ using CustomFreeFun = void*(void*, void*);
void* custom_malloc(std::size_t size)
{
static CustomMallocFun* _malloc = (CustomMallocFun*)get_address("custom_malloc"sv);
static void* _alloc_base = OnHeapPointer<void>(*(size_t*)get_address("malloc_base"sv)).decode();
static void* _alloc_base = OnHeapPointer<void>(*(size_t*)get_address("malloc_base"sv)).decode(); // probably should be decode_local
return _malloc(_alloc_base, size);
}
void custom_free(void* mem)
{
static CustomFreeFun* _free = (CustomFreeFun*)get_address("custom_free"sv);
static void* _alloc_base = OnHeapPointer<void>(*(size_t*)get_address("malloc_base"sv)).decode();
static void* _alloc_base = OnHeapPointer<void>(*(size_t*)get_address("malloc_base"sv)).decode(); // probably should be decode_local
_free(_alloc_base, mem);
}
13 changes: 7 additions & 6 deletions src/game_api/entities_mounts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <utility> // for pair

#include "entities_chars.hpp" // for PowerupCapable
#include "math.h" // for Vec2

class Movable;
struct SoundMeta;
Expand Down Expand Up @@ -32,12 +33,12 @@ class Mount : public PowerupCapable
flags = flags | 0x20000;
}

virtual std::pair<float, float>& get_special_offset(std::pair<float, float>& offset) = 0; // gets special offset for the raider when jumping on mount
virtual std::pair<float, float>& v96(std::pair<float, float>& value) = 0; // gets something for when crouching on mount
virtual bool used_double_jump() = 0; // checks can_doublejump and unknown9b
virtual uint32_t v98(bool) = 0; // returns some constant value
virtual uint32_t v99() = 0; // returns some constant value
virtual void play_jump_on_sound() = 0; // checks if it has rider
virtual Vec2& get_special_offset(Vec2& offset) = 0; // gets special offset for the raider when jumping on mount
virtual Vec2& v96(Vec2& value) = 0; // gets something for when crouching on mount
virtual bool used_double_jump() = 0; // checks can_doublejump and unknown9b
virtual uint32_t v98(bool) = 0; // returns some constant value
virtual uint32_t v99() = 0; // returns some constant value
virtual void play_jump_on_sound() = 0; // checks if it has rider
virtual void remove_rider() = 0;
virtual float v102() = 0; // get offset? mech returns 0.9, the rest 0.5
virtual uint32_t v103() = 0; // returns some constant value
Expand Down
8 changes: 4 additions & 4 deletions src/game_api/entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ void Entity::perform_teleport(uint8_t delta_x, uint8_t delta_y)
tp(this, delta_x, delta_y);
}

std::pair<float, float> Entity::position() const
Vec2 Entity::position() const
{
auto [x_pos, y_pos] = position_self();

Expand Down Expand Up @@ -203,7 +203,7 @@ std::tuple<float, float, uint8_t> get_position(uint32_t uid)
{
Entity* ent = get_entity_ptr(uid);
if (ent)
return std::make_tuple(ent->position().first, ent->position().second, ent->layer);
return std::make_tuple(ent->position().x, ent->position().y, ent->layer);

return {0.0f, 0.0f, (uint8_t)0};
}
Expand Down Expand Up @@ -236,8 +236,8 @@ std::tuple<float, float> get_velocity(uint32_t uid)
else if (ent->is_liquid())
{
auto liquid_engine = State::get().get_correct_liquid_engine(ent->type->id);
vx = liquid_engine->entity_velocities->first;
vy = liquid_engine->entity_velocities->second;
vx = liquid_engine->entity_velocities->x;
vy = liquid_engine->entity_velocities->y;
}
if (ent->overlay)
{
Expand Down
8 changes: 4 additions & 4 deletions src/game_api/entity.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "entity_db.hpp" // for EntityDB
#include "entity_structs.hpp" // for CollisionInfo
#include "layer.hpp" // for EntityList
#include "math.hpp" // for AABB
#include "math.hpp" // for AABB, Vec2

struct RenderInfo;
struct Texture;
Expand Down Expand Up @@ -115,7 +115,7 @@ class Entity
return (size_t)this;
}

std::pair<float, float> position() const;
Vec2 position() const;

void teleport(float dx, float dy, bool s, float vx, float vy, bool snap);
void teleport_abs(float dx, float dy, float vx, float vy);
Expand Down Expand Up @@ -188,9 +188,9 @@ class Entity
return overlaps_with(other_left, other_bottom, other_right, other_top);
}

std::pair<float, float> position_self() const
Vec2 position_self() const
{
return std::pair<float, float>(x, y);
return Vec2{x, y};
}
void remove_item(uint32_t item_uid);

Expand Down
17 changes: 6 additions & 11 deletions src/game_api/entity_db.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include "aliases.hpp" // for ENT_TYPE, LAYER, TEXTURE, STRINGID
#include "color.hpp" // for Color
#include "containers/custom_vector.hpp" // for custom_vector
#include "containers/game_unordered_map.hpp" // for game_unordered_map
#include "containers/identity_hasher.hpp" // for identity_hasher
#include "entity_structs.hpp" // for CollisionInfo
Expand Down Expand Up @@ -131,28 +132,22 @@ struct EntityItem
}
};

struct EntityBucket
{
void** begin;
void** current; // Note, counts down from end to begin instead of up from begin to end :shrug:
void** end;
};
struct EntityPool
{
std::uint32_t slot_size;
std::uint32_t initial_slots;
std::uint32_t slots_growth;
std::uint32_t current_slots;
std::uint64_t _ulong_0;
EntityBucket* _some_bucket;
EntityBucket* bucket;
std::uint64_t unknown;
custom_vector<size_t>* pools_begin; // saved the first entity address that causes the slot size to increase (including the initial)
custom_vector<size_t>* empty_buckets; // empty entity slots
};
struct EntityFactory
{
EntityDB types[0x395];
bool type_set[0x395];
std::unordered_map<std::uint32_t, OnHeapPointer<EntityPool>> entity_instance_map;
EntityMap entity_map;
std::unordered_map<std::uint32_t, OnHeapPointer<EntityPool>> entity_instance_map; // game_unorderedmap probably
EntityMap entity_map; // game_unorderedmap probably
void* _ptr_7;
};

Expand Down
Loading

0 comments on commit dd300d1

Please sign in to comment.