Skip to content

Commit

Permalink
Merge branch 'main' into stable
Browse files Browse the repository at this point in the history
  • Loading branch information
afwbkbc committed Jun 9, 2024
2 parents 766bcd6 + c609ec1 commit 540bcc2
Show file tree
Hide file tree
Showing 49 changed files with 1,460 additions and 893 deletions.
126 changes: 37 additions & 89 deletions gse/default/factions.gls.js
Original file line number Diff line number Diff line change
@@ -1,92 +1,40 @@
return [

// SMAC
['GAIANS', {
name: 'Gaians',
files: {
pcx: 'gaians.pcx'
}
}],
['HIVE', {
name: 'Hive',
files: {
pcx: 'hive.pcx'
}
}],
['UNIVERSITY', {
name: 'University',
files: {
pcx: 'univ.pcx'
}
}],
['MORGANITES', {
name: 'Morganites',
files: {
pcx: 'morgan.pcx'
}
}],
['SPARTANS', {
name: 'Spartans',
files: {
pcx: 'spartans.pcx'
}
}],
['BELIEVERS', {
name: 'Believers',
files: {
pcx: 'believe.pcx'
}
}],
['PEACEKEEPERS', {
name: 'Peacekeepers',
files: {
pcx: 'peace.pcx'
}
}],

// SMACX
['CONSCIOUSNESS', {
name: 'Consciousness',
files: {
pcx: 'cyborg.pcx'
}
}],
['PIRATES', {
name: 'Pirates',
files: {
pcx: 'pirates.pcx'
}
}],
['DRONES', {
name: 'Drones',
files: {
pcx: 'drone.pcx'
}
}],
['ANGELS', {
name: 'Angels',
files: {
pcx: 'angels.pcx'
}
}],
['PLANETCULT', {
name: 'Planet Cult',
files: {
pcx: 'fungboy.pcx'
}
}],
['CARETAKERS', {
name: 'Caretakers',
files: {
pcx: 'caretake.pcx'
const faction = (id, name, text_color, border_color, pcx, extra) => {
return [id, {
name: name,
colors: {
text: text_color,
border: border_color,
},
is_progenitor: true
}],
['USURPERS', {
name: 'Usurpers',
files: {
pcx: 'usurper.pcx'
bases: {
render: {
type: 'sprite_grid',
file: pcx,
grid_x: 1, grid_y: 1,
cell_width: 100, cell_height: 75,
//cell_cx: 50, cell_cy: 38,
cell_padding: 1,
/*scale_x: 0.7,
scale_y: 0.7,*/
}
},
is_progenitor: true
}],
} + extra];
};

const factions = [
faction('GAIANS', 'Gaians', #to_color(16, 228, 0), #to_color(0, 252, 0), 'gaians.pcx', {}),
faction('HIVE', 'Hive', #to_color(0, 97, 255), #to_color(0, 0, 255), 'hive.pcx', {}),
faction('UNIVERSITY', 'University', #to_color(216, 224, 244), #to_color(255, 255, 255), 'univ.pcx', {}),
faction('MORGANITES', 'Morganites', #to_color(255, 255, 0), #to_color(255, 255, 0), 'morgan.pcx', {}),
faction('SPARTANS', 'Spartans', #to_color(136, 166, 166), #to_color(0, 0, 0), 'spartans.pcx', {}),
faction('BELIEVERS', 'Believers', #to_color(224, 156, 28), #to_color(236, 92, 0), 'believe.pcx', {}),
faction('PEACEKEEPERS', 'Peacekeepers', #to_color(164, 176, 232), #to_color(164, 176, 232), 'peace.pcx', {}),
faction('CONSCIOUSNESS', 'Consciousness', #to_color(44, 128, 104), #to_color(44, 128, 104), 'cyborg.pcx', {}),
faction('PIRATES', 'Pirates', #to_color(0, 255, 255), #to_color(0, 255, 255), 'pirates.pcx', {}),
faction('DRONES', 'Drones', #to_color(173, 196, 192), #to_color(136, 12, 12), 'drone.pcx', {}),
faction('ANGELS', 'Angels', #to_color(103, 91, 181), #to_color(103, 91, 181), 'angels.pcx', {}),
faction('PLANETCULT', 'Planet Cult', #to_color(232, 84, 84), #to_color(232, 84, 84), 'fungboy.pcx', {}),
faction('CARETAKERS', 'Caretakers', #to_color(116, 156, 56), #to_color(116, 156, 56), 'caretake.pcx', {is_progenitor: true}),
faction('USURPERS', 'Usurpers', #to_color(212, 208, 116), #to_color(212, 208, 116), 'usurper.pcx', {is_progenitor: true}),
];

return factions;
22 changes: 21 additions & 1 deletion src/base/Base.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#include <atomic>

#ifdef DEBUG
#include <chrono>
#endif

#include "Base.h"

#include "engine/Engine.h"
Expand Down Expand Up @@ -35,9 +39,25 @@ const std::string& Base::GetLocalName() const {
return m_name;
}

#ifdef DEBUG
static uint64_t last_time = 0;
#endif

void Base::Log( const std::string& text ) const {
if ( g_engine != NULL ) {
g_engine->GetLogger()->Log( "<" + GetName() + "> " + text );
#ifdef DEBUG
const auto time = std::chrono::high_resolution_clock::now().time_since_epoch().count();
const auto duration = last_time
? time - last_time
: 0;
last_time = time;
#endif
g_engine->GetLogger()->Log(
#ifdef DEBUG
"[+" + std::to_string( duration ) + "ns] " +
#endif
"<" + GetName() + "> " + text
);
}
}

Expand Down
66 changes: 36 additions & 30 deletions src/game/animation/FramesRow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,33 +21,39 @@ FramesRow::FramesRow(
const std::string& sound_file
)
: Def( id, AT_FRAMES_ROW, duration_ms, scale_x, scale_y, sound_file )
, m_file( file )
, m_row_x( row_x )
, m_row_y( row_y )
, m_frame_width( frame_width )
, m_frame_height( frame_height )
, m_frame_center_x( frame_center_x )
, m_frame_center_y( frame_center_y )
, m_frame_padding( frame_padding )
, m_frames_count( frames_count )
, m_frames_per_row( frames_per_row ) {
, m_render(
{
file,
row_x,
row_y,
frame_width,
frame_height,
frame_padding,
frame_center_x,
frame_center_y,
frames_count,
frames_per_row,
scale_x,
scale_y
}
) {
//
}

const std::string FramesRow::ToString( const std::string& prefix ) const {
return (std::string)
TS_OBJ_BEGIN( "FramesRow" ) +
TS_OBJ_PROP_STR( "id", m_id ) +
TS_OBJ_PROP_STR( "file", m_file ) +
TS_OBJ_PROP_NUM( "row_x", m_row_x ) +
TS_OBJ_PROP_NUM( "row_y", m_row_y ) +
TS_OBJ_PROP_NUM( "frame_width", m_frame_width ) +
TS_OBJ_PROP_NUM( "frame_height", m_frame_height ) +
TS_OBJ_PROP_NUM( "frame_center_x", m_frame_center_x ) +
TS_OBJ_PROP_NUM( "frame_center_y", m_frame_center_y ) +
TS_OBJ_PROP_NUM( "frame_padding", m_frame_padding ) +
TS_OBJ_PROP_NUM( "frames_count", m_frames_count ) +
TS_OBJ_PROP_NUM( "frames_per_row", m_frames_per_row ) +
TS_OBJ_PROP_STR( "file", m_render.file ) +
TS_OBJ_PROP_NUM( "row_x", m_render.row_x ) +
TS_OBJ_PROP_NUM( "row_y", m_render.row_y ) +
TS_OBJ_PROP_NUM( "frame_width", m_render.frame_width ) +
TS_OBJ_PROP_NUM( "frame_height", m_render.frame_height ) +
TS_OBJ_PROP_NUM( "frame_center_x", m_render.frame_center_x ) +
TS_OBJ_PROP_NUM( "frame_center_y", m_render.frame_center_y ) +
TS_OBJ_PROP_NUM( "frame_padding", m_render.frame_padding ) +
TS_OBJ_PROP_NUM( "frames_count", m_render.frames_count ) +
TS_OBJ_PROP_NUM( "frames_per_row", m_render.frames_per_row ) +
TS_OBJ_PROP_NUM( "scale_x", m_scale_x ) +
TS_OBJ_PROP_NUM( "scale_y", m_scale_y ) +
TS_OBJ_PROP_NUM( "duration_ms", m_duration_ms ) +
Expand All @@ -56,16 +62,16 @@ const std::string FramesRow::ToString( const std::string& prefix ) const {
}

void FramesRow::Serialize( types::Buffer& buf, const FramesRow* def ) {
buf.WriteString( def->m_file );
buf.WriteInt( def->m_row_x );
buf.WriteInt( def->m_row_y );
buf.WriteInt( def->m_frame_width );
buf.WriteInt( def->m_frame_height );
buf.WriteInt( def->m_frame_center_x );
buf.WriteInt( def->m_frame_center_y );
buf.WriteInt( def->m_frame_padding );
buf.WriteInt( def->m_frames_count );
buf.WriteInt( def->m_frames_per_row );
buf.WriteString( def->m_render.file );
buf.WriteInt( def->m_render.row_x );
buf.WriteInt( def->m_render.row_y );
buf.WriteInt( def->m_render.frame_width );
buf.WriteInt( def->m_render.frame_height );
buf.WriteInt( def->m_render.frame_center_x );
buf.WriteInt( def->m_render.frame_center_y );
buf.WriteInt( def->m_render.frame_padding );
buf.WriteInt( def->m_render.frames_count );
buf.WriteInt( def->m_render.frames_per_row );
}

FramesRow* FramesRow::Unserialize(
Expand Down
13 changes: 3 additions & 10 deletions src/game/animation/FramesRow.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include <cstdint>

#include "Types.h"

#include "Def.h"

namespace game {
Expand All @@ -28,16 +30,7 @@ class FramesRow : public Def {
const std::string& sound_file
);

const std::string m_file;
const uint16_t m_row_x;
const uint16_t m_row_y;
const uint16_t m_frame_width;
const uint16_t m_frame_height;
const uint16_t m_frame_padding;
const uint16_t m_frame_center_x;
const uint16_t m_frame_center_y;
const uint8_t m_frames_count;
const uint8_t m_frames_per_row;
sprite_render_info_t m_render = {};

const std::string ToString( const std::string& prefix ) const override;

Expand Down
18 changes: 18 additions & 0 deletions src/game/animation/Types.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#pragma once

#include <string>
#include <cstdint>

namespace game {
namespace animation {

Expand All @@ -8,5 +11,20 @@ enum animation_type_t {
AT_FRAMES_ROW,
};

struct sprite_render_info_t {
std::string file;
uint16_t row_x;
uint16_t row_y;
uint16_t frame_width;
uint16_t frame_height;
uint16_t frame_padding;
uint16_t frame_center_x;
uint16_t frame_center_y;
uint8_t frames_count;
uint8_t frames_per_row;
float scale_x;
float scale_y;
};

}
}
42 changes: 39 additions & 3 deletions src/game/bindings/Factions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "gse/Exception.h"
#include "gse/type/Object.h"
#include "gse/type/String.h"
#include "gse/type/Int.h"
#include "gse/type/Float.h"
#include "gse/type/Undefined.h"
#include "gse/type/Bool.h"
#include "game/bindings/Bindings.h"
Expand Down Expand Up @@ -31,14 +33,48 @@ BINDING_IMPL( factions ) {

rules::Faction faction = { id, name };

N_GETPROP( files, faction_def, "files", Object );
N_GETPROP( pcx_file, files, "pcx", String );
faction.ImportPCX( pcx_file );
N_GETPROP( colors, faction_def, "colors", Object );
N_GETPROP_UNWRAP( colors_text, colors, "text", types::Color );
N_GETPROP_UNWRAP( colors_border, colors, "border", types::Color );
faction.m_colors = { colors_text, colors_border };

N_GETPROP_OPT_BOOL( is_progenitor, faction_def, "is_progenitor")
if ( is_progenitor ) {
faction.m_flags |= rules::Faction::FF_PROGENITOR;
}

N_GETPROP( bases_def, faction_def, "bases", Object );
N_GETPROP( bases_render_def, bases_def, "render", Object );

N_GETPROP( bases_render_type, bases_render_def, "type", String );
if ( bases_render_type == "sprite_grid" ) {
N_GETPROP( file, bases_render_def, "file", String );
N_GETPROP( grid_x, bases_render_def, "grid_x", Int );
N_GETPROP( grid_y, bases_render_def, "grid_y", Int );
N_GETPROP( cell_width, bases_render_def, "cell_width", Int );
N_GETPROP( cell_height, bases_render_def, "cell_height", Int );
N_GETPROP_OPT( size_t, cell_cx, bases_render_def, "cell_cx", Int, cell_width / 2 );
N_GETPROP_OPT( size_t, cell_cy, bases_render_def, "cell_cy", Int, cell_height / 2 );
N_GETPROP( cell_padding, bases_render_def, "cell_padding", Int );
N_GETPROP_OPT( float, scale_x, bases_render_def, "scale_x", Float, 1.0f );
N_GETPROP_OPT( float, scale_y, bases_render_def, "scale_y", Float, 1.0f );
faction.m_bases_render = {
file,
(size_t)grid_x,
(size_t)grid_y,
(size_t)cell_width,
(size_t)cell_height,
cell_cx,
cell_cy,
(size_t)cell_padding,
scale_x,
scale_y
};
}
else {
ERROR( gse::EC.GAME_ERROR, "Unsupported bases render type: " + bases_render_type );
}

factions.insert({ id, faction });
factions_order.push_back( id );
return VALUE( gse::type::Undefined );
Expand Down
Loading

0 comments on commit 540bcc2

Please sign in to comment.