Skip to content

Commit

Permalink
contracts: optimization: use IntrospectPacked
Browse files Browse the repository at this point in the history
  • Loading branch information
credence0x committed Jul 27, 2024
1 parent 129d83f commit 492931b
Show file tree
Hide file tree
Showing 27 changed files with 67 additions and 68 deletions.
2 changes: 1 addition & 1 deletion contracts/src/models/bank/bank.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use eternum::alias::ID;
use starknet::ContractAddress;

// Used as helper struct throughout the world
#[derive(Copy, Drop, Serde)]
#[derive(IntrospectPacked, Copy, Drop, Serde)]
#[dojo::model]
pub struct Bank {
#[key]
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/models/bank/liquidity.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl IntrospectFixed of Introspect<Fixed> {
}
}

#[derive(Copy, Drop, Serde)]
#[derive(IntrospectPacked, Copy, Drop, Serde)]
#[dojo::model]
pub struct Liquidity {
#[key]
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/models/bank/market.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl IntrospectFixed of Introspect<Fixed> {
}
}

#[derive(Copy, Drop, Serde)]
#[derive(IntrospectPacked, Copy, Drop, Serde)]
#[dojo::model]
pub struct Market {
#[key]
Expand Down
5 changes: 2 additions & 3 deletions contracts/src/models/buildings.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use eternum::models::resources::{Resource, ResourceCustomImpl, ResourceCost};

//todo we need to define border of innner hexes

#[derive(PartialEq, Copy, Drop, Serde)]
#[derive(IntrospectPacked, PartialEq, Copy, Drop, Serde)]
#[dojo::model]
pub struct Building {
#[key]
Expand All @@ -36,7 +36,7 @@ pub struct Building {
outer_entity_id: ID,
}

#[derive(PartialEq, Copy, Drop, Serde)]
#[derive(IntrospectPacked, PartialEq, Copy, Drop, Serde)]
#[dojo::model]
pub struct BuildingQuantityv2 {
#[key]
Expand All @@ -48,7 +48,6 @@ pub struct BuildingQuantityv2 {


#[derive(PartialEq, Copy, Drop, Serde, Introspect)]
#[dojo::model]
enum BuildingCategory {
None,
Castle,
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/models/capacity.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use eternum::models::quantity::{Quantity, QuantityCustomTrait};
use eternum::models::weight::{Weight};


#[derive(Copy, Drop, Serde)]
#[derive(IntrospectPacked, Copy, Drop, Serde)]
#[dojo::model]
pub struct Capacity {
#[key]
Expand Down
10 changes: 5 additions & 5 deletions contracts/src/models/combat.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use eternum::utils::number::NumberTrait;
const STRENGTH_PRECISION: u256 = 10_000;


#[derive(Copy, Drop, Serde, Default)]
#[derive(IntrospectPacked, Copy, Drop, Serde, Default)]
#[dojo::model]
pub struct Health {
#[key]
Expand Down Expand Up @@ -290,7 +290,7 @@ impl ArmyQuantityTracker of ArmyQuantityTrackerTrait {
}
}

#[derive(Copy, Drop, Serde, Default)]
#[derive(IntrospectPacked, Copy, Drop, Serde, Default)]
#[dojo::model]
pub struct Army {
#[key]
Expand Down Expand Up @@ -385,7 +385,7 @@ impl ArmyCustomImpl of ArmyCustomTrait {
}


#[derive(Copy, Drop, Serde, Default)]
#[derive(IntrospectPacked, Copy, Drop, Serde, Default)]
#[dojo::model]
pub struct Protector {
#[key]
Expand All @@ -400,7 +400,7 @@ impl ProtectorCustomImpl of ProtectorCustomTrait {
}
}

#[derive(Copy, Drop, Serde, Default)]
#[derive(IntrospectPacked, Copy, Drop, Serde, Default)]
#[dojo::model]
pub struct Protectee {
#[key]
Expand Down Expand Up @@ -428,7 +428,7 @@ impl ProtecteeCustomImpl of ProtecteeCustomTrait {
}


#[derive(Copy, Drop, Serde, Default)]
#[derive(IntrospectPacked, Copy, Drop, Serde, Default)]
#[dojo::model]
pub struct Battle {
#[key]
Expand Down
38 changes: 19 additions & 19 deletions contracts/src/models/config.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use starknet::ContractAddress;
// GLOBAL CONFIGS
//

#[derive(Copy, Drop, Serde)]
#[derive(IntrospectPacked, Copy, Drop, Serde)]
#[dojo::model]
pub struct WorldConfig {
#[key]
Expand All @@ -22,7 +22,7 @@ pub struct WorldConfig {
realm_l2_contract: ContractAddress,
}

#[derive(Copy, Drop, Serde)]
#[derive(IntrospectPacked, Copy, Drop, Serde)]
#[dojo::model]
pub struct RealmFreeMintConfig {
#[key]
Expand All @@ -32,7 +32,7 @@ pub struct RealmFreeMintConfig {
}


#[derive(Copy, Drop, Serde)]
#[derive(IntrospectPacked, Copy, Drop, Serde)]
#[dojo::model]
pub struct RoadConfig {
#[key]
Expand All @@ -42,7 +42,7 @@ pub struct RoadConfig {
speed_up_by: u64
}

#[derive(Copy, Drop, Serde)]
#[derive(IntrospectPacked, Copy, Drop, Serde)]
#[dojo::model]
pub struct HyperstructureResourceConfig {
#[key]
Expand All @@ -57,7 +57,7 @@ pub struct HyperstructureResourceConfig {
// that it's a config for one specific entity type?
// and not the same as world config
// e.g. EntityTypeCapacityConfig?
#[derive(Copy, Drop, Serde)]
#[derive(IntrospectPacked, Copy, Drop, Serde)]
#[dojo::model]
pub struct CapacityConfig {
#[key]
Expand All @@ -76,7 +76,7 @@ impl CapacityConfigCustomImpl of CapacityConfigCustomTrait {
}

// speed
#[derive(Copy, Drop, Serde)]
#[derive(IntrospectPacked, Copy, Drop, Serde)]
#[dojo::model]
pub struct SpeedConfig {
#[key]
Expand All @@ -88,7 +88,7 @@ pub struct SpeedConfig {
}


#[derive(Copy, Drop, Serde)]
#[derive(IntrospectPacked, Copy, Drop, Serde)]
#[dojo::model]
pub struct MapExploreConfig {
#[key]
Expand All @@ -100,7 +100,7 @@ pub struct MapExploreConfig {
}


#[derive(Copy, Drop, Serde)]
#[derive(IntrospectPacked, Copy, Drop, Serde)]
#[dojo::model]
pub struct TickConfig {
#[key]
Expand All @@ -110,7 +110,7 @@ pub struct TickConfig {
tick_interval_in_seconds: u64
}

#[derive(Copy, Drop, Serde)]
#[derive(IntrospectPacked, Copy, Drop, Serde)]
#[dojo::model]
pub struct StaminaConfig {
#[key]
Expand Down Expand Up @@ -169,7 +169,7 @@ impl TickImpl of TickTrait {


// weight
#[derive(Copy, Drop, Serde)]
#[derive(IntrospectPacked, Copy, Drop, Serde)]
#[dojo::model]
pub struct WeightConfig {
#[key]
Expand All @@ -189,7 +189,7 @@ impl WeightConfigCustomImpl of WeightConfigCustomTrait {
}
}

#[derive(Copy, Drop, Serde)]
#[derive(IntrospectPacked, Copy, Drop, Serde)]
#[dojo::model]
pub struct LevelingConfig {
#[key]
Expand All @@ -212,7 +212,7 @@ pub struct LevelingConfig {
resource_3_cost_count: u32
}

#[derive(Copy, Drop, Serde)]
#[derive(IntrospectPacked, Copy, Drop, Serde)]
#[dojo::model]
pub struct ProductionConfig {
#[key]
Expand All @@ -226,7 +226,7 @@ pub struct ProductionConfig {
}


#[derive(Copy, Drop, Serde)]
#[derive(IntrospectPacked, Copy, Drop, Serde)]
#[dojo::model]
pub struct BankConfig {
#[key]
Expand All @@ -236,7 +236,7 @@ pub struct BankConfig {
lp_fee_denom: u128,
}

#[derive(Copy, Drop, Serde)]
#[derive(IntrospectPacked, Copy, Drop, Serde)]
#[dojo::model]
pub struct BuildingConfig {
#[key]
Expand Down Expand Up @@ -264,7 +264,7 @@ impl BuildingConfigCustomImpl of BuildingConfigCustomTrait {
}
}

#[derive(Copy, Drop, Serde)]
#[derive(IntrospectPacked, Copy, Drop, Serde)]
#[dojo::model]
pub struct TroopConfig {
#[key]
Expand Down Expand Up @@ -300,7 +300,7 @@ impl TroopConfigCustomImpl of TroopConfigCustomTrait {
}


#[derive(Copy, Drop, Serde)]
#[derive(IntrospectPacked, Copy, Drop, Serde)]
#[dojo::model]
pub struct BattleConfig {
#[key]
Expand All @@ -316,7 +316,7 @@ impl BattleConfigCustomImpl of BattleConfigCustomTrait {
}


#[derive(Copy, Drop, Serde)]
#[derive(IntrospectPacked, Copy, Drop, Serde)]
#[dojo::model]
pub struct BuildingCategoryPopConfig {
#[key]
Expand All @@ -327,7 +327,7 @@ pub struct BuildingCategoryPopConfig {
capacity: u32, // increase capacity by this amount
}

#[derive(Copy, Drop, Serde)]
#[derive(IntrospectPacked, Copy, Drop, Serde)]
#[dojo::model]
pub struct PopulationConfig {
#[key]
Expand All @@ -349,7 +349,7 @@ impl HyperstructureConfigCustomImpl of HyperstructureConfigCustomTrait {
}
}

#[derive(Copy, Drop, Serde)]
#[derive(IntrospectPacked, Copy, Drop, Serde)]
#[dojo::model]
pub struct HasClaimedStartingResources {
#[key]
Expand Down
6 changes: 3 additions & 3 deletions contracts/src/models/guild.cairo
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use eternum::alias::ID;
use starknet::ContractAddress;

#[derive(Copy, Drop, Serde)]
#[derive(IntrospectPacked, Copy, Drop, Serde)]
#[dojo::model]
pub struct Guild {
#[key]
Expand All @@ -10,15 +10,15 @@ pub struct Guild {
member_count: u16
}

#[derive(Copy, Drop, Serde)]
#[derive(IntrospectPacked, Copy, Drop, Serde)]
#[dojo::model]
pub struct GuildMember {
#[key]
address: ContractAddress,
guild_entity_id: ID
}

#[derive(Copy, Drop, Serde)]
#[derive(IntrospectPacked, Copy, Drop, Serde)]
#[dojo::model]
pub struct GuildWhitelist {
#[key]
Expand Down
4 changes: 2 additions & 2 deletions contracts/src/models/hyperstructure.cairo
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use eternum::alias::ID;
use starknet::ContractAddress;

#[derive(Copy, Drop, Serde)]
#[derive(IntrospectPacked, Copy, Drop, Serde)]
#[dojo::model]
pub struct Progress {
#[key]
Expand All @@ -11,7 +11,7 @@ pub struct Progress {
amount: u128,
}

#[derive(Copy, Drop, Serde)]
#[derive(IntrospectPacked, Copy, Drop, Serde)]
#[dojo::model]
pub struct Contribution {
#[key]
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/models/level.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use eternum::constants::{LevelIndex};
use eternum::models::config::{LevelingConfig};
use eternum::models::resources::{ResourceCost};

#[derive(Copy, Drop, Serde)]
#[derive(IntrospectPacked, Copy, Drop, Serde)]
#[dojo::model]
pub struct Level {
#[key]
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/models/map.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use eternum::alias::ID;
use eternum::models::position::Coord;
use eternum::utils::map::biomes::Biome;

#[derive(Copy, Drop, Serde)]
#[derive(IntrospectPacked, Copy, Drop, Serde)]
#[dojo::model]
pub struct Tile {
#[key]
Expand Down
4 changes: 2 additions & 2 deletions contracts/src/models/metadata.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use eternum::alias::ID;

// a way to store the type of the entity in addition
// to the list of components which we already have
#[derive(Copy, Drop, Serde)]
#[derive(IntrospectPacked, Copy, Drop, Serde)]
#[dojo::model]
pub struct EntityMetadata {
#[key]
Expand All @@ -16,7 +16,7 @@ pub struct EntityMetadata {
// using an index and the foreign key
// see CreateCaravan for an example
// TODO: change ForeignKey to CaravanMember and stop using general purpose components
#[derive(Copy, Drop, Serde)]
#[derive(IntrospectPacked, Copy, Drop, Serde)]
#[dojo::model]
pub struct ForeignKey {
#[key]
Expand Down
4 changes: 2 additions & 2 deletions contracts/src/models/movable.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use eternum::constants::WORLD_CONFIG_ID;
use eternum::models::config::{SpeedConfig};
use eternum::models::position::Coord;
// speed seconds per km
#[derive(Copy, Drop, Serde)]
#[derive(IntrospectPacked, Copy, Drop, Serde)]
#[dojo::model]
pub struct Movable {
#[key]
Expand Down Expand Up @@ -36,7 +36,7 @@ impl MovableCustomImpl of MovableCustomTrait {
// DISCUSS: separated from the Movable component because
// we want to attach an ArrivalTime to the trading order
// without having to attach a Movable component to the order
#[derive(Copy, Drop, Serde)]
#[derive(IntrospectPacked, Copy, Drop, Serde)]
#[dojo::model]
pub struct ArrivalTime {
#[key]
Expand Down
4 changes: 2 additions & 2 deletions contracts/src/models/name.cairo
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use eternum::alias::ID;

#[derive(Copy, Drop, Serde)]
#[derive(IntrospectPacked, Copy, Drop, Serde)]
#[dojo::model]
pub struct AddressName {
#[key]
address: felt252,
name: felt252
}

#[derive(Copy, Drop, Serde)]
#[derive(IntrospectPacked, Copy, Drop, Serde)]
#[dojo::model]
pub struct EntityName {
#[key]
Expand Down
Loading

0 comments on commit 492931b

Please sign in to comment.