repo_name
stringlengths 6
97
| path
stringlengths 3
341
| text
stringlengths 8
1.02M
|
---|---|---|
turesnake/tprPixelGames | src/Engine/map/MapAltitude.h | <reponame>turesnake/tprPixelGames
/*
* ====================== MapAltitude.h =======================
* -- tpr --
* CREATE -- 2019.03.11
* MODIFY --
* ----------------------------------------------------------
* 每个 pix / mapEnt/field 都拥有自身的 高度信息。
* ----------------------------
*/
#ifndef TPR_MAP_ALTITUDE_H
#define TPR_MAP_ALTITUDE_H
//------------------- Engine --------------------//
#include "IntVec.h"
//-- [mem]
class MapAltitude{
public:
MapAltitude() = default;
explicit MapAltitude( double val_ ){
this->init( val_ );
}
//-- 仅表达是否为land,很可能为 临水区域 --
inline bool is_land() const noexcept{
return (this->val >= 0);
}
constexpr inline int get_val()const noexcept{ return this->val; }
constexpr inline int get_lvl()const noexcept{ return this->lvl; }
private:
void init( double altiVal_from_gpgpu_ );
//===== vals =====//
int val {0}; //- [-100,100]
// 静态值,最简单的alti,不应该直接用此值。
// >=0 时 为 land
int lvl {0}; //- [-5,2]
// "高度等级" 基于 val,单受到更多因素的影响
// 推荐 主用此值来表达 “高度”
// --------
// -5: 水下最深处,go无法通行
// -1 ~ -4: 水下,根据深度,逐渐降低 go 的移动速度
// 0: 水上,“临水区” 颜色特别。比如有沙滩
// 1: “次临水区” 一个过渡区
// 2: 彻底的陆地
};
/* ===========================================================
* operator <
* -----------------------------------------------------------
* -- 通过这个 "<" 运算符重载,IntVec2 类型将支持 set.find()
*/
inline constexpr bool operator < ( const MapAltitude &a_, const MapAltitude &b_ )noexcept{
return ( a_.get_val() < b_.get_val() );
}
inline constexpr bool operator > ( const MapAltitude &a_, const MapAltitude &b_ )noexcept{
return ( a_.get_val() > b_.get_val() );
}
#endif
|
turesnake/tprPixelGames | src/Engine/map/fieldKey.h | <reponame>turesnake/tprPixelGames
/*
* ====================== fieldKey.h =======================
* -- tpr --
* CREATE -- 2019.03.06
* MODIFY --
* ----------------------------------------------------------
* MapField "id": (int)w + (int)h
* ----------------------------
*/
#ifndef TPR_FIELD_KEY_H
#define TPR_FIELD_KEY_H
//-------------------- CPP --------------------//
#include <vector>
//-------------------- Engine --------------------//
#include "tprAssert.h"
#include "config.h"
#include "IntVec.h"
#include "MapCoord.h"
using fieldKey_t = uint64_t;
fieldKey_t fieldMPos_2_key_inn( IntVec2 fieldMPos_ )noexcept; //- 不推荐外部代码使用
IntVec2 fieldKey_2_mpos( fieldKey_t key_ )noexcept;
IntVec2 anyMPos_2_fieldMPos( IntVec2 anyMPos_ )noexcept;
fieldKey_t anyMPos_2_fieldKey( IntVec2 anyMPos_ )noexcept;
fieldKey_t anyDPos_2_fieldKey( const glm::dvec2 &anyDPos_ )noexcept;
fieldKey_t fieldMPos_2_fieldKey( IntVec2 fieldMPos_ )noexcept;
/* ===========================================================
* fieldMPos_2_key_inn
* -----------------------------------------------------------
* -- 传入 field 左下角mpos,获得 field key val
* 此函数并不安全(没有检测 参数是否为 fieldMpos)所以只能在模块内部使用
* param: fieldMPos_ - 必须为 field 左下角mpos。
*/
inline fieldKey_t fieldMPos_2_key_inn( IntVec2 fieldMPos_ )noexcept{
fieldKey_t key {};
int *ptr = (int*)&key;
*ptr = fieldMPos_.x;
ptr++;
*ptr = fieldMPos_.y;
//--------
return key;
}
/* ===========================================================
* fieldKey_2_mpos
* -----------------------------------------------------------
* -- 传入某个key,生成其 field 的 mpos
*/
inline IntVec2 fieldKey_2_mpos( fieldKey_t key_ )noexcept{
IntVec2 mpos {};
int *ptr = (int*)&key_;
//---
mpos.x = *ptr;
ptr++;
mpos.y = *ptr;
//---
return mpos;
}
/* ===========================================================
* anyMPos_2_fieldMPos
* -----------------------------------------------------------
* -- 传入 任意 mapent 的 mpos,获得其 所在 field 的 mpos(chunk左下角)
*/
inline IntVec2 anyMPos_2_fieldMPos( IntVec2 anyMPos_ )noexcept{
return ( floorDiv(anyMPos_, ENTS_PER_FIELD_D) * ENTS_PER_FIELD<> );
}
/* ===========================================================
* anyMPos_2_fieldKey
* -----------------------------------------------------------
* -- 这个函数会使得调用者代码 隐藏一些bug。
* 在明确自己传入的参数就是 fieldMPos 时,推荐使用 fieldMPos_2_sectionKey()
* param: anyMPos_ -- 任意 mapent 的 mpos
*
* 在目前版本中,mapent 通过此函数,简单地被分配到各个 field...
* 这个办法并不完美,但迫不得已...
*
*/
inline fieldKey_t anyMPos_2_fieldKey( IntVec2 anyMPos_ )noexcept{
IntVec2 fieldMPos = anyMPos_2_fieldMPos( anyMPos_ );
return fieldMPos_2_key_inn( fieldMPos );
}
inline fieldKey_t anyDPos_2_fieldKey( const glm::dvec2 &anyDPos_ )noexcept{
IntVec2 fieldMPos = anyMPos_2_fieldMPos( dpos_2_mpos(anyDPos_) ); //-- 未来做优化
return fieldMPos_2_key_inn( fieldMPos );
}
/* ===========================================================
* fieldMPos_2_fieldKey
* -----------------------------------------------------------
* -- 当使用者 确定自己传入的参数就是 fieldMPos, 使用此函数
* 如果参数不为 fieldMPos,直接报错。
*/
inline fieldKey_t fieldMPos_2_fieldKey( IntVec2 fieldMPos_ )noexcept{
tprAssert( anyMPos_2_fieldMPos(fieldMPos_) == fieldMPos_ ); //- tmp
return fieldMPos_2_key_inn( fieldMPos_ );
}
#endif
|
turesnake/tprPixelGames | src/Engine/animFrameSet/animSubspeciesId.h | /*
* =================== animSubspeciesId.h ==========================
* -- tpr --
* CREATE -- 2019.09.10
* MODIFY --
* ----------------------------------------------------------
*/
#ifndef TPR_ANIM_SUB_SPEC_ID_H
#define TPR_ANIM_SUB_SPEC_ID_H
//------------------- CPP --------------------//
#include <cstdint> // uint8_t
using animSubspeciesId_t = uint32_t;
// 一个空的 id 值, 表示生成此值的代码,本来就不打算生成一个 实际的id
// 用于 蓝图分配
// 有些 go,会在 具象go class 中,自行分配 sudId
inline constexpr animSubspeciesId_t EMPTY_animSubspeciesId { static_cast<animSubspeciesId_t>(-1) };
inline bool is_empty_animSubspeciesId( animSubspeciesId_t id_ )noexcept{
return (id_ == EMPTY_animSubspeciesId);
}
#endif
|
turesnake/tprPixelGames | src/Engine/collision/collide_oth.h | <gh_stars>100-1000
/*
* ====================== collide_oth.h ==========================
* -- tpr --
* CREATE -- 2019.08.30
* MODIFY --
* ----------------------------------------------------------
* Only used in Collision.cpp !!!
* ------------
*/
#ifndef TPR_COLLIDE_OTH_H
#define TPR_COLLIDE_OTH_H
#include "pch.h"
//-------------------- Engine --------------------//
#include "ColliderType.h"
#include "NineDirection.h"
#include "MapCoord.h"
#include "SpeedLevel.h" // tmp
void init_for_colliOth_inn()noexcept;
inline double calc_cos( const glm::dvec2 &a_, const glm::dvec2 &b_ ) noexcept {
return glm::dot(glm::normalize(a_), glm::normalize(b_) );
}
/* ===========================================================
* collideCheck_between_2_arcs_in_same_circular
* -----------------------------------------------------------
* return:
* -- true: collide
* -- flase: not collide
*/
inline bool collideCheck_between_2_arcs_in_same_circular( const glm::dvec2 &forward_1_,
double halfRadian_1_,
const glm::dvec2 &forward_2_,
double halfRadian_2_ )noexcept{
tprAssert( (halfRadian_1_>=0.0) && (halfRadian_2_>=0.0) );
double cosV = calc_cos( forward_1_, forward_2_ ); //- 为负值时,角度大于 90 度
double radian = acos(cosV);
return (radian < (halfRadian_1_+halfRadian_2_)) ? true : false;
}
/* ===========================================================
* calc_halfRadian_in_2_intersect_circulars
* -----------------------------------------------------------
* 2个确认相交的圆(do,be)计算 doCir 相交圆弧 半弧度值
*/
inline double calc_halfRadian_in_2_intersect_circulars( double rd_, double rb_, double totalLen_ ){
tprAssert( (rd_+rb_) > totalLen_ );
double cosVal = (rd_*rd_ - rb_*rb_ + totalLen_*totalLen_) / (2.0 * totalLen_ * rd_);
return acos(cosVal);
}
/* ===========================================================
* collideState_from_circular_2_circular
* -----------------------------------------------------------
* just check if dogoCir is collide with begoCir
* 优化: dogo 使用统一的 半径,不再需要 参数提供
*/
inline CollideState collideState_from_circular_2_circular( const glm::dvec2 &dogoCirDPos_,
const Circular &begoCir_,
double threshold_ ) noexcept {
glm::dvec2 offVec = begoCir_.dpos - dogoCirDPos_;
double sum_of_two_raidus = Circular::radius_for_dogo + begoCir_.radius;
//-- Avoid Radical Sign / 避免开根号 --
double off = (offVec.x * offVec.x) + (offVec.y * offVec.y) -
(sum_of_two_raidus * sum_of_two_raidus);
if( is_closeEnough<double>(off, 0.0, threshold_*threshold_) ){
return CollideState::Adjacent;
}else if( off < 0.0 ){
return CollideState::Intersect;
}else{
return CollideState::Separate;
}
}
const std::unordered_set<NineDirection> &collect_Adjacent_nearbyMapEnts( const glm::dvec2 &dogoDPos_, IntVec2 dogoMPos_ );
glm::dvec2 calc_obstructNormalVec_from_AdjacentMapEnts( const glm::dvec2 &moveVec_,
const glm::dvec2 &dogoDPos_,
IntVec2 dogoMPos_,
const std::set<NineDirection> &AdjacentMapEnts_ )noexcept;
/* ===========================================================
* fastCollideCheck_from_arc_2_circular
* -----------------------------------------------------------
* return:
* -- true: collide
* -- flase: not collide
*/
inline bool fastCollideCheck_from_arc_2_circular( const ArcLine &dogoArc_,
const Circular &begoCir_,
double threshold_ ) noexcept{
double rd = dogoArc_.radius;
double rb = begoCir_.radius;
double sum_of_two_raidus = rd + rb;
glm::dvec2 offVec = begoCir_.dpos - dogoArc_.dpos;
//-- Avoid Radical Sign / 避免开根号 --
double lenSquare = (offVec.x * offVec.x) + (offVec.y * offVec.y);
double lenImprecise = lenSquare - (sum_of_two_raidus * sum_of_two_raidus);
if( is_closeEnough<double>(lenImprecise, 0.0, threshold_*threshold_) ){ // Adjacent
return collideCheck_between_2_arcs_in_same_circular(offVec,
0.0,
dogoArc_.forward,
dogoArc_.halfRadian );
}else if( lenImprecise > 0.0 ){ //Separate
return false;
}else{ // Intersect
double len = sqrt(lenSquare); //- 开根号开销略大...
double minRadius = tprMin( rd, rb );
double maxRadius = tprMax( rd, rb );
if( (len+minRadius) <= maxRadius ){ //- 小圆被大圆彻底包含
return true; // IMM
}
double halfRadian = calc_halfRadian_in_2_intersect_circulars(rd, rb, len);
return collideCheck_between_2_arcs_in_same_circular(offVec,
halfRadian,
dogoArc_.forward,
dogoArc_.halfRadian );
}
}
/* ===========================================================
* is_dogoCircular_leave_begoCircular
* -----------------------------------------------------------
* 当方向背离时,将不进行碰撞检测
* 优化: dogo 使用统一的 半径,不再需要 参数提供
*/
inline bool is_dogoCircular_leave_begoCircular( const glm::dvec2 &moveVec_,
const glm::dvec2 &dogoCirDPos_,
const Circular &begoCir_ ) noexcept {
glm::dvec2 dogo_2_bego = begoCir_.dpos - dogoCirDPos_;
double cosVal = calc_cos( moveVec_, dogo_2_bego );
return (cosVal <= 0.0) ? true : false;
}
//-- 仅用于 第一阶段,此时知道现成的 墙壁法向量,直接使用即可
inline bool is_dogo_leave_begoSquares_easy( const glm::dvec2 &moveVec_,
const glm::dvec2 &obstructNormalVec_ ) noexcept {
double cosVal = calc_cos( moveVec_, (-1.0 * obstructNormalVec_) );
return (cosVal <= 0.0) ? true : false;
}
//-- 仅用于 第二阶段,此时的 墙壁法向量,需要重新计算
inline bool is_dogo_leave_begoSquares_2( const glm::dvec2 &moveVec_,
const glm::dvec2 &dogoDPos_,
IntVec2 dogoMPos_,
IntVec2 targetMPos_
) noexcept {
glm::dvec2 obNormVec {};
//-- dogo 在 mp 的那个方位
auto dir = intVec2_2_nineDirection( dogoMPos_ - targetMPos_ );
switch (dir){
case NineDirection::Left:
case NineDirection::Right:
case NineDirection::Top:
case NineDirection::Bottom:
obNormVec = nineDirection_2_dVec2( dir );
break;
case NineDirection::LeftTop:
case NineDirection::LeftBottom:
case NineDirection::RightTop:
case NineDirection::RightBottom:
case NineDirection::Center: // Center 也许不该这么处理 ...
obNormVec = dogoDPos_ - mpos_2_midDPos(targetMPos_);
break;
default:
tprAssert(0);
break;
}
//----
double cosVal = calc_cos( moveVec_, (-1.0 * obNormVec) );
return (cosVal <= 0.0) ? true : false;
}
/* ===========================================================
* circularCast [traditional solution]
* -----------------------------------------------------------
* if collision has been confirmed between bego and dogo.
* call this func to calculate the colliPoint in motion vector.
* 优化: dogo 使用统一的 半径,不再需要 参数提供
* ---
* return:
* t is a scale
*/
inline double circularCast( const glm::dvec2 &moveVec_,
const glm::dvec2 &dogoCirDPos_,
const Circular &begoCir_ ) noexcept {
double sum_of_2_radius = Circular::radius_for_dogo + begoCir_.radius;
glm::dvec2 dogo_2_bego = begoCir_.dpos - dogoCirDPos_;
//---
glm::dvec2 dogo_2_begoInn = calc_innVec( moveVec_, dogo_2_bego );
double thirdEdge = sqrt(sum_of_2_radius*sum_of_2_radius - dogo_2_begoInn.y*dogo_2_begoInn.y);
return (( std::abs(dogo_2_begoInn.x) - thirdEdge) / glm::length(moveVec_));
}
/* ===========================================================
* calc_slideMoveVec
* -----------------------------------------------------------
* 位移向量 会被 阻挡向量 阻挡,退化为一个 平行与 阻挡向量的 分量。
* 当 位移向量 和 阻挡向量 夹角很小时,会主动对结果叠加一个增值,让它滑动得快些
*/
inline glm::dvec2 calc_slideMoveVec( const glm::dvec2 &moveVec_,
const glm::dvec2 &obstructVec_ ) noexcept {
glm::dvec2 dogo_2_oth = -1.0 * obstructVec_; // anti
double pct = std::abs(calc_innVec(dogo_2_oth, moveVec_).x) / glm::length(dogo_2_oth);
glm::dvec2 newMoveVec = (moveVec_ - dogo_2_oth*pct) * 1.0;
return limit_moveSpeed( newMoveVec );
//-- 偏转后速度会下降,尤其在与 cir_bego 的碰撞中,游戏体验不够好
// 人为地增加速度
// 同时确保 速度不越界
}
/* ===========================================================
* calc_intersectX
* -----------------------------------------------------------
* 位移向量,与水平线: y=y_ 相交,求 碰撞 t值
* 求直线 y=y_ 与向量 root_2_tail_ 所在直线的交点,的 x 值
* return:
* double: newX
* double: t
*/
inline std::pair<double,double> cast_with_horizonLine( const glm::dvec2 &moveVec_,
const glm::dvec2 &dogoDPos_,
double y_ ) noexcept {
tprAssert( moveVec_.y != 0.0 );
double t = (y_ - dogoDPos_.y) / moveVec_.y; // 允许为负值,以便 dogo 从相交状态后退
double newX = dogoDPos_.x + moveVec_.x*t;
return { newX, t };
}
inline std::pair<double,double> cast_with_verticalLine( const glm::dvec2 &moveVec_,
const glm::dvec2 &dogoDPos_,
double x_ ) noexcept {
tprAssert( moveVec_.x != 0.0 );
double t = (x_ - dogoDPos_.x) / moveVec_.x; // 允许为负值,以便 dogo 从相交状态后退
double newY = dogoDPos_.y + moveVec_.y*t;
return { newY, t };
}
std::pair<bool,double> cast_with_mapent( const glm::dvec2 &moveVec_,
const glm::dvec2 &dogoDPos_,
IntVec2 mpos_ )noexcept;
#endif
|
turesnake/tprPixelGames | src/Engine/resource/esrc_window.h | <reponame>turesnake/tprPixelGames
/*
* ========================= esrc_window.h ==========================
* -- tpr --
* CREATE -- 2019.04.19
* MODIFY --
* ----------------------------------------------------------
*/
#ifndef TPR_ESRC_WINDOW_H
#define TPR_ESRC_WINDOW_H
//=== *** glad FIRST, glfw SECEND *** ===
// Don't include glfw3.h ALONE!!!
#include<glad/glad.h>
#include<GLFW/glfw3.h>
//-------------------- Engine --------------------//
#include "IntVec.h"
namespace esrc {//------------------ namespace: esrc -------------------------//
GLFWwindow *get_windowPtr();
void set_windowPtr( GLFWwindow *newPtr_ );
}//---------------------- namespace: esrc -------------------------//
#endif
|
turesnake/tprPixelGames | src/Engine/gameObj/goDataForCreate/GoAssemblePlan.h | /*
* ===================== GoAssemblePlan.h =====================
* -- tpr --
* CREATE -- 2019.10.10
* MODIFY --
* ----------------------------------------------------------
*/
#ifndef TPR_GO_ASSEMBLE_PLAN_H
#define TPR_GO_ASSEMBLE_PLAN_H
#include "pch.h"
//------------------- CPP --------------------//
#include <variant>
//------------------- Engine --------------------//
#include "goLabelId.h"
#include "GameObjType.h"
#include "ID_Manager.h"
#include "NineDirection.h"
#include "BrokenLvl.h"
#include "AnimActionEName.h"
#include "GoAltiRange.h"
#include "FloorGoType.h"
#include "RenderLayerType.h"
#include "ShaderType.h"
#include "ColliDataFromJson.h"
// 一个 go-action,可以由数个 gomesh-action 组合而成
//
class GoAssemblePlanSet{
public:
class GoMeshEnt{
public:
std::string goMeshName {}; // 索引key
//===
std::string animFrameSetName {};
std::string animLabel {};
glm::dvec2 dposOff {}; // gomesh-dposoff based on go-dpos
double zOff {};
AnimActionEName animActionEName {};
RenderLayerType renderLayerType {};
ShaderType shaderType {};
bool isVisible {};
bool isAutoInit {};
NineDirection default_dir {};
BrokenLvl default_brokenLvl {};
// dir / broken 数据,存在 3 层设置
// -1- 未在 asm.json 中显式声明,直接使用默认值
// -2- 在 asm.json 中显式声明,以上两种记录的都是 default 值
// -3- 在 蓝图 / byHand 中显式设置 实际值,将会覆盖 default 值
// 每个后一层都会覆盖前一层
//------- optional_vals -------//
std::optional<FloorGoLayer> floorGoLayer { std::nullopt }; // only for FloorGo
};
// 一个 go 实例,由数个 gomesh 以及其他数据 组合而成
class Plan{
public:
using id_t = uint32_t;
//---
Plan()=default;
inline const GoMeshEnt &get_goMeshEntRef( const std::string &name_ )const noexcept{
tprAssert( this->gomeshs.find(name_) != this->gomeshs.end() );
return this->gomeshs.at(name_);
}
//===== vals =====//
std::unordered_map<std::string, GoAssemblePlanSet::GoMeshEnt> gomeshs {};
GoAltiRangeLabel goAltiRangeLabel {};
std::unique_ptr<ColliDataFromJson> colliDataFromJsonUPtr {nullptr};
//------- optional_vals -------//
//======== static ========//
static ID_Manager id_manager;
};
//========== Self Vals ==========//
GoAssemblePlanSet()=default;
inline Plan &create_new_plan( goLabelId_t labelId_ )noexcept{
//----- id -----//
Plan::id_t id = Plan::id_manager.apply_a_u32_id();
if( labelId_ != DEFAULT_GO_LABEL_ID ){
auto [insertIt1, insertBool1] = this->ids.insert({ labelId_, std::vector<Plan::id_t>{} }); // insert or find
insertIt1->second.push_back(id);
}else{
// do nothing, goLabelId::Default not belong to any type
}
this->allIds.push_back(id); // always
//----- instance -----//
auto [insertIt2, insertBool2] = this->planUPtrs.insert({ id, std::make_unique<Plan>() });
tprAssert( insertBool2 );
//----- ret -----//
return *(insertIt2->second);
}
inline const Plan &apply_a_plan( goLabelId_t labelId_, size_t randUVal_ )const noexcept{
//----- id -----//
size_t idx {};
Plan::id_t id {};
if( labelId_ == DEFAULT_GO_LABEL_ID ){
tprAssert( !this->allIds.empty() );
idx = (randUVal_ + 152375) % this->allIds.size(); // apply a id directly from all ids
id = this->allIds.at( idx );
}else{
tprAssert( this->ids.find(labelId_) != this->ids.end() );
auto &cRef = this->ids.at(labelId_);
tprAssert( !cRef.empty() );
idx = (randUVal_ + 152375) % cRef.size(); // from target idPool
id = this->ids.at(labelId_).at( idx );
}
//--- ret ---//
tprAssert( this->planUPtrs.find(id) != this->planUPtrs.end() );
return *(this->planUPtrs.at(id));
}
//======= static =======//
// json 数据中,每个新类型,都被登记为一个 id 号
inline static void insert_2_goLabelIds( const std::string &str_ )noexcept{
// 参数表示 默认值时,不需要登记
if( (str_=="DEFAULT") || (str_=="Default") || (str_=="") ){
return;
}
GoAssemblePlanSet::goLabelIds.insert( GoAssemblePlanSet::hasher(str_) ); // maybe
}
// 在程序体内,一律用 id 号来传递
static goLabelId_t str_2_goLabelId( const std::string &str_ )noexcept{
if( (str_=="DEFAULT") || (str_=="Default") || (str_=="") ){ // 表示自己,不为任何类型
return GoAssemblePlanSet::DEFAULT_GO_LABEL_ID;
}
size_t id = GoAssemblePlanSet::hasher(str_);
tprAssert( GoAssemblePlanSet::goLabelIds.find(id) != GoAssemblePlanSet::goLabelIds.end() );
return id;
}
private:
std::unordered_map<goLabelId_t, std::vector<Plan::id_t>> ids {};
std::vector<Plan::id_t> allIds {};
//---
std::unordered_map<Plan::id_t, std::unique_ptr<Plan>> planUPtrs {};
//======= static =======//
static std::unordered_set<goLabelId_t> goLabelIds;
// 制作成全局容器不够精确,假设某种 go,都含有 goLabel: "Sml"
// 另一种go,也想要检测 "Sml" 时,只能获知,总数据中含有,而不是,自身的数据中含有
// 先不做修改
// ...
static std::hash<std::string> hasher;
static const size_t DEFAULT_GO_LABEL_ID;
};
namespace json {//-------- namespace: json --------------//
void parse_single_goAssemblePlanJsonFile( const std::string &path_file_ );
}//------------- namespace: json end --------------//
#endif
|
turesnake/tprPixelGames | src/Engine/collision/signInMapEnts/SignInMapEnts_Circle.h | <gh_stars>100-1000
/*
* ====================== SignInMapEnts_Circle.h ==========================
* -- tpr --
* CREATE -- 2019.09.04
* MODIFY --
* ----------------------------------------------------------
*/
#ifndef TPR_SignInMapEnts_CIRCLE_H
#define TPR_SignInMapEnts_CIRCLE_H
#include "pch.h"
//-------------------- CPP --------------------//
#include <utility> // pair
//-------------------- Engine --------------------//
#include "MapCoord.h"
// 仅有 majorGo: cir 会用到本实例
// arc 压根不参与 moveCollide
// squ 压根不移动
class SignInMapEnts_Circle{
using F_get_colliPointDPosOffsRef = std::function<const std::vector<glm::dvec2> &()>;
public:
SignInMapEnts_Circle( const glm::dvec2 &newGoDPos_,
F_get_colliPointDPosOffsRef func_1_ ):
get_colliPointDPosOffsRefFunc(func_1_)
{
bool out = this->forecast_signINMapEnts( newGoDPos_ );
tprAssert( out );
this->sync_currentSignINMapEnts_from_future();
}
//------------------------------------//
// 使用位置:
//--1-- 当一个 majorGo 新生成时,传入参数 go.dpos,制作最初的 SignINMapEnts 数据,
// 然后 call sync_currentSignINMapEnts_from_new()
//--2-- 每一移动帧, 调用此函数来生成 addsDels,
// 然后做碰撞检测。在此期间,这个函数可能被调用多次,但都不会改写 currentSignINMapEnts
// ----
// 直到确认位移后,才调用 sync_currentSignINMapEnts_from_new(),同步数据
//-----
// param: newRootAnchorDPos_ = currentDPos + moveVec
// ret:
// adds/dels 是否发生了变化
inline bool forecast_signINMapEnts( const glm::dvec2 &newGoDPos_ )noexcept{
if( !this->is_forecast_called ){
this->is_forecast_called = true;
}
this->futureAdds.clear();
this->futureDels.clear();
this->futureSignINMapEnts.clear();
//-- update news --
for( const auto &i : this->get_colliPointDPosOffsRefFunc() ){
this->futureSignINMapEnts.insert( dpos_2_mpos(i+newGoDPos_) );
}
//-- adds --
for( const auto &i : this->futureSignINMapEnts ){
if( this->currentSignINMapEnts.find(i) == this->currentSignINMapEnts.end() ){
this->futureAdds.push_back( i );//- copy
}
}
//-- dels --
for( const auto &i : this->currentSignINMapEnts ){
if( this->futureSignINMapEnts.find(i) == this->futureSignINMapEnts.end() ){
this->futureDels.push_back( i );//- copy
}
}
//-- return --
return (!this->futureAdds.empty()) || (!this->futureDels.empty());
}
//-- 同步数据 --
inline void sync_currentSignINMapEnts_from_future()noexcept{
tprAssert( this->is_forecast_called );
this->is_forecast_called = false;
//- only swap when change happened
// 确保在调用此函数时,addsdels 一定发生了更新
tprAssert( !(this->futureAdds.empty() && this->futureDels.empty()) );
this->currentAdds.swap( this->futureAdds );
this->currentDels.swap( this->futureDels );
this->currentSignINMapEnts.swap( this->futureSignINMapEnts );
//-- swap 后的 future容器 会在下次 调用 forecast_signINMapEnts 时自动清理 --
}
inline const std::set<IntVec2> &get_currentSignINMapEntsRef() const noexcept{ return this->currentSignINMapEnts; }
inline const std::set<IntVec2> &get_futureSignINMapEntsRef() const noexcept{ return this->futureSignINMapEnts; }
inline const std::vector<IntVec2> &get_currentAddsRef() const noexcept{ return this->currentAdds; }
inline const std::vector<IntVec2> &get_currentDelsRef() const noexcept{ return this->currentDels; }
private:
F_get_colliPointDPosOffsRef get_colliPointDPosOffsRefFunc {nullptr};
//--- current ---//
std::set<IntVec2> currentSignINMapEnts {}; //- 每一帧移动后,go都会及时更新自己当前登记的 mapents
std::vector<IntVec2> currentAdds {}; //- 每帧移动后,将要被新登记的 mapents
std::vector<IntVec2> currentDels {}; //- 每帧移动后,将要被取消登记的 mapents
//--- future ---//
// each time call forecast_(), the future datas will be update
// only sync to current datas when sync_() is called
std::set<IntVec2> futureSignINMapEnts {};
std::vector<IntVec2> futureAdds {};
std::vector<IntVec2> futureDels {};
//----- flags -----//
bool is_forecast_called {false}; //- 协调 forecast 和 sync 两个函数的 次序。
// forecast 可以被调用多次
// 每次调用 sync 之前,forecast 至少要被调用一次
};
#endif
|
turesnake/tprPixelGames | src/Engine/coordinate/Coordinate.h | /*
* ====================== Coordinate.h ==========================
* -- tpr --
* CREATE -- 2019.11.15
* MODIFY --
* ----------------------------------------------------------
* self defined coordinate system
* ------------
*/
#ifndef TPR_COORD_H
#define TPR_COORD_H
#include "pch.h"
//-------------------- Engine --------------------//
#include "NineDirection.h"
class Coordinate{
public:
Coordinate( const glm::dvec2 &xVec_, const glm::dvec2 &yVec_ ):
xVec(xVec_),
yVec(yVec_),
denominator( xVec.x * yVec.y - xVec.y * yVec.x )
{
this->init();
}
//-- 将外部世界坐标系的值,转换成 客制坐标系内的 对应值
inline glm::dvec2 calc_innDPos( const glm::dvec2 &outDPos_ )const noexcept{
return glm::dvec2{
(this->yVec.y * outDPos_.x - this->yVec.x * outDPos_.y) / this->denominator,
(this->xVec.x * outDPos_.y - this->xVec.y * outDPos_.x) / this->denominator
};
}
//-- 将客制坐标系内的 值,转换成 外部世界坐标的 对应值
inline glm::dvec2 calc_outDPos( const glm::dvec2 &innDPos_ )const noexcept{
return glm::dvec2{ this->xVec.x * innDPos_.x + this->yVec.x * innDPos_.y,
this->xVec.y * innDPos_.x + this->yVec.y * innDPos_.y };
}
inline const glm::dvec2 &get_normalVec_in_outCoord( NineDirection dir_ )const noexcept{
tprAssert( this->normalVecs_in_outCoord.find(dir_) != this->normalVecs_in_outCoord.end() );
return this->normalVecs_in_outCoord.at(dir_);
}
//----- get -----//
inline const glm::dvec2 &get_rightHand()const noexcept{ return this->rightHand; }
inline const glm::dvec2 &get_xVec()const noexcept{ return this->xVec; }
inline const glm::dvec2 &get_yVec()const noexcept{ return this->yVec; }
inline double get_denominator()const noexcept{ return this->denominator; }
private:
void init()noexcept;
//----- vals -----//
glm::dvec2 xVec;
glm::dvec2 yVec;
double denominator; // in order to make the calc easy
glm::dvec2 rightHand {}; // 本坐标系 x方向 单位向量,在 outCoord 中的值
// 目前用于,修正 input 方向健输入
//-- 每个坐标系内部,都存在一个对齐于原点的 正方形。
// 将这个正方形扭曲,变成其在 外部坐标系的样子,并记录其4条边,在外部坐标系的 对外法线向量
std::unordered_map<NineDirection, glm::dvec2> normalVecs_in_outCoord {};
};
#endif
|
turesnake/tprPixelGames | src/Engine/resource/esrc_behaviour.h | <reponame>turesnake/tprPixelGames
/*
* ========================= esrc_behaviour.h ==========================
* -- tpr --
* CREATE -- 2019.04.19
* MODIFY --
* ----------------------------------------------------------
*/
#ifndef TPR_ESRC_BEHAVIOUR_H
#define TPR_ESRC_BEHAVIOUR_H
//-------------------- Engine --------------------//
#include "Behaviour.h"
namespace esrc {//------------------ namespace: esrc -------------------------//
void init_behaviour();
Behaviour &get_behaviour();
void call_scriptMain(); //- 调用 脚本层 入口函数
}//---------------------- namespace: esrc -------------------------//
#endif
|
turesnake/tprPixelGames | src/Engine/actionFSM/ActionFSM.h | /*
* ========================= ActionFSM.h ==========================
* -- tpr --
* CREATE -- 2019.02.13
* MODIFY --
* ----------------------------------------------------------
* 动作状态机
* -------------
* 一个 go实例拥有一个 actionFSM实例,
* 统管 所有 gomesh实例的 动画播放,
* 控制 move 指令输入,(进一步控制 collision )
*
* ----------------------------
*/
#ifndef TPR_ACTION_FSM_H
#define TPR_ACTION_FSM_H
#include "pch.h"
//-------------------- Engine --------------------//
#include "functorTypes.h"
//- 节点状态 --
class ActionState{
public:
F_void enterFunc {nullptr}; //- 入口函数
F_void exitFunc {nullptr}; //- 出口函数
};
//-- need --//
class GameObj;
class ActionFSM{
public:
ActionFSM() = default;
inline void init( GameObj *goPtr_ )noexcept{
this->goPtr = goPtr_;
}
inline ActionState *insert_new_state( const std::string &name_ )noexcept{
// ***| INSERT FIRST, INIT LATER |***
ActionState state {};
auto [insertIt, insertBool] = states.emplace( name_, state ); //- copy
tprAssert( insertBool );
// init...
return &(insertIt->second);
}
private:
GameObj *goPtr {nullptr};
std::unordered_map<std::string, ActionState> states {};
//- 暂用 string 来索引,效率可能有点低...
};
#endif
|
turesnake/tprPixelGames | src/Engine/map/ChunkMemState.h | /*
* ======================= ChunkMemState.h =======================
* -- tpr --
* CREATE -- 2019.07.09
* MODIFY --
* ----------------------------------------------------------
*/
#ifndef TPR_CHUNK_MEM_STATE_H
#define TPR_CHUNK_MEM_STATE_H
// chunk 在游戏运行期间的 所有状态
// ---
// OnCreating 和 Active 的临界点,在 esrc::insert_and_init_new_chunk() 中
// 在此之后,chunk部分的数据已经初始化完毕,但是 其上的 go,尚未创建
// ---
// 在目前版本中,一个chunk,一旦进入 WaitForRelease,将永不能被取回。
// 如果发现,想要新建的 chunk,正在 WaitForRelease 状态,说明参数设置有问题,直接报错。
// 这能简化很多 问题
// ---
// 每一渲染帧,renderPool 会重新加载 active态的 chunk,并排序
// 当把一个chunk,改成 WaitForRelease,它就已经无法被渲染出来了。
//
// ---
// 有必要再添加一个 WaitForDB ...
//
enum class ChunkMemState : int{
NotExist,
WaitForCreate,
OnCreating,
Active,
WaitForRelease,
OnReleasing
};
#endif
|
turesnake/tprPixelGames | deps/tprInUnix/tprFileModeT.h | <reponame>turesnake/tprPixelGames<gh_stars>100-1000
/*
* ========================= tprFileModeT.h ==========================
* -- tpr --
* CREATE -- 2018.10.15
* MODIFY --
* ----------------------------------------------------------
* support all files/libs
* mode_t
* ----------------------------
*/
#ifndef TPR_FILE_MODE_H_
#define TPR_FILE_MODE_H_
//- rw-------
#ifndef RW_______
#define RW_______ ( S_IRUSR | S_IWUSR )
#endif
//- rwx------
#ifndef RWX______
#define RWX______ ( RW_______ | S_IXUSR )
#endif
//- rw-r--r--
#ifndef RW_R__R__
#define RW_R__R__ ( RW_______ | S_IRGRP | S_IROTH )
#endif
//- rw-rw-r--
#ifndef RW_RW_R__
#define RW_RW_R__ ( RW_R__R__ | S_IWGRP )
#endif
//- rwxr-xr-x
#ifndef RWXR_XR_X
#define RWXR_XR_X ( RW_R__R__ | S_IXUSR | S_IXGRP | S_IXOTH )
#endif
#endif
|
turesnake/tprPixelGames | src/Engine/tprDebug/timeLog.h | /*
* ========================= timeLog.h ==========================
* -- tpr --
* CREATE -- 2019.07.14
* MODIFY --
* ----------------------------------------------------------
*/
#ifndef TPR_TIME_LOG_H
#define TPR_TIME_LOG_H
//------------------- CPP --------------------//
#include <map>
namespace tprDebug {//---------- namespace: tprDebug --------------//
void init_timeLog();
void collect_deltaTime(double deltaTime_);
void process_and_echo_timeLog();
size_t get_frameIdx();
}//-------------------- namespace: tprDebug end --------------//
#endif
|
turesnake/tprPixelGames | src/Engine/fileIO/fileIO.h | /*
* ======================= fileIO.h ==========================
* -- tpr --
* 创建 -- 2019.07.08
* 修改 --
* ----------------------------------------------------------
*/
#ifndef TPR_FILE_IO_H
#define TPR_FILE_IO_H
//--------------- CPP ------------------//
#include <string>
#include <memory>
std::unique_ptr<std::string> read_a_file( const std::string &filePath_ );
#endif
|
turesnake/tprPixelGames | src/Engine/resource/esrc_ecoSysPlan.h | <gh_stars>100-1000
/*
* ========================= esrc_ecoSysPlan.h ==========================
* -- tpr --
* CREATE -- 2019.04.19
* MODIFY --
* ----------------------------------------------------------
*/
#ifndef TPR_ESRC_ECOSYS_PLAN_H
#define TPR_ESRC_ECOSYS_PLAN_H
//-------------------- CPP --------------------//
#include <unordered_map>
//-------------------- Engine --------------------//
#include "EcoSysPlan.h"
namespace esrc {//------------------ namespace: esrc -------------------------//
void init_ecoSysPlanes();
EcoSysPlan &insert_new_ecoSysPlan( EcoSysPlanType type_ );
EcoSysPlan *get_ecoSysPlanPtr( ecoSysPlanId_t ecoId_ );
ecoSysPlanId_t apply_a_ecoSysPlanId_by_type( EcoSysPlanType type_, size_t ecoObjUWeight_ );
ecoSysPlanId_t apply_a_rand_ecoSysPlanId( size_t ecoObjUWeight_ );
}//---------------------- namespace: esrc -------------------------//
#endif
|
turesnake/tprPixelGames | src/Engine/map/occupyWeight.h | /*
* ========================== occupyWeight.h =======================
* -- tpr --
* CREATE -- 2019.03.22
* MODIFY --
* ----------------------------------------------------------
* 那些通过 "覆盖法/抢占法" 来对规划一个区域的 模块,
* 需要一种机制来区分 区域四顶点 的 “抢占强势程度”。
* 4顶点 的 occupyWeight 值不应该 出现相同。
* ------------------------
*/
#ifndef TPR_OCCUPY_WEIGHT_H
#define TPR_OCCUPY_WEIGHT_H
//-------------------- Engine --------------------//
#include "IntVec.h"
using occupyWeight_t = int;
occupyWeight_t calc_occupyWeight( IntVec2 oddEven_, size_t idx_ );
#endif
|
turesnake/tprPixelGames | src/Engine/resource/esrc_thread.h | <reponame>turesnake/tprPixelGames<gh_stars>100-1000
/*
* ========================= esrc_thread.h ==========================
* -- tpr --
* CREATE -- 2019.04.25
* MODIFY --
* ----------------------------------------------------------
*/
#ifndef TPR_ESRC_THREAD_H
#define TPR_ESRC_THREAD_H
namespace esrc {//------------------ namespace: esrc -------------------------//
void start_jobThreads();
void join_jobThreads();
}//---------------------- namespace: esrc -------------------------//
#endif
|
turesnake/tprPixelGames | src/Engine/ecoSys/EcoObjMemState.h | <gh_stars>100-1000
/*
* ======================= EcoObjMemState.h =======================
* -- tpr --
* CREATE -- 2019.07.09
* MODIFY --
* ----------------------------------------------------------
*/
#ifndef TPR_ECO_OBJ_MEM_STATE_H
#define TPR_ECO_OBJ_MEM_STATE_H
// ecoobj 在游戏运行期间的 所有状态
//
enum class EcoObjMemState : int{
NotExist,
OnCreating,
Active,
OnReleasing // ecoobj 可以被当场删除,不需要在队列中等待
};
#endif
|
turesnake/tprPixelGames | src/Engine/mesh/Mesh.h | /*
* ========================= Mesh.h ==========================
* -- tpr --
* CREATE -- 2019.01.07
* MODIFY --
* ----------------------------------------------------------
* A BASIC Mesh class.
* handle single texture.
* ----------------------------
*/
#ifndef TPR_MESH_H
#define TPR_MESH_H
//=== *** glad FIRST, glfw SECEND *** ===
// Don't include glfw3.h ALONE!!!
#include <glad/glad.h>
//--- glm - 0.9.9.5 ---
#include "glm_no_warnings.h"
//-------------------- CPP --------------------//
#include <vector>
//-------------------- Engine --------------------//
#include "ShaderProgram.h" //-- each Mesh instance,will bind a shader
#include "AnimFrameSet.h"
class Mesh{
public:
Mesh() = default;
void init( GLuint texName_ );
void draw();
//--------------------------//
inline void set_shader_program( ShaderProgram *sp_ )noexcept{
this->shaderPtr = sp_;
}
inline void set_texName( GLuint texName_ )noexcept{
this->texName = texName_;
}
inline void set_translate( const glm::vec3 &v_ )noexcept{
this->translate_val = v_;
this->isMat4Change = true;
}
inline void set_scale( const glm::vec3 &v_ )noexcept{
this->scale_val = v_;
this->isMat4Change = true;
}
//------- get -------//
//- 通过 translate_val.z 值 来给 待渲染的 meshs 排序 --
inline float get_render_z()const noexcept{ return this->translate_val.z; }
//======== flags ========//
bool isVisible {false};
private:
void update_mat4_model(); //-- 重新计算 model矩阵
//======== vals ========//
GLuint texName {0};
ShaderProgram *shaderPtr {nullptr};
GLuint VAO {}; // simple copy from esrc_VAOVBO
GLsizei pointNums {}; // glDrawArrays() param
//+++++++++ 与 图元 矩阵计算 有关的 变量 ++++++++++++
glm::mat4 mat4_model = glm::mat4(1.0); //-- 每个 物体obj 都私有一个 模型矩阵
//-- 自动初始化为 标准矩阵
//-- 位移/旋转/缩放 变化向量。
glm::vec3 translate_val {};
glm::vec3 scale_val {glm::vec3(1.0f, 1.0f, 1.0f)}; //- 缩放比例(用半径来缩放)
bool isMat4Change {true}; //- 位移/旋转/缩放 是否被改写。
//- 若被改写,就要重新计算 mat4_model
};
#endif
|
turesnake/tprPixelGames | src/Engine/dynamicParam/dyParams.h | <gh_stars>100-1000
/*
* ======================== dyParams.h ==========================
* -- tpr --
* CREATE -- 2019.10.05
* MODIFY --
* ----------------------------------------------------------
*/
#ifndef TPR_DY_PARAMS_H
#define TPR_DY_PARAMS_H
//-------------------- CPP --------------------//
#include <vector>
#include <set>
#include <cstdint> // uint8_t
//-------------------- Engine --------------------//
#include "DyParam.h"
#include "GoDataForCreate.h"
struct DyParams_GoDataForCreate{
const GoDataForCreate *goDataPtr {};
};
#endif
|
turesnake/tprPixelGames | src/Engine/actionSwitch/ActionSwitch.h | <gh_stars>100-1000
/*
* ========================= ActionSwitch.h ==========================
* -- tpr --
* CREATE -- 2019.02.01
* MODIFY --
* ----------------------------------------------------------
* 一个 go实例 在不同的状态,需要切换到不同的 action
* 一部分 切换工作 是在 引擎内部调用的。
* 通过本模块来 统一管理
* -----
* 可能会被 ActionFSM 取代...
* ----------------------------
*/
#ifndef TPR_ACTION_SWITCH_H
#define TPR_ACTION_SWITCH_H
#include "pch.h"
//-------------------- Engine --------------------//
#include "ActionSwitchType.h"
#include "BoolBitMap.h"
//--- need ---//
class GameObj;
class ActionSwitch{
public:
using F_ACTION_SWITCH = std::function<void( GameObj&, ActionSwitchType)>;
explicit ActionSwitch( GameObj &goRef_ ):
goRef(goRef_)
{
bitMap.resize( 64,1 ); // bitMap容器 占了 64 个元素
//- 随着 ActionSwitchType 种类的增多,
// 这个值将不断扩大
}
inline void bind_func( const F_ACTION_SWITCH &func_ )noexcept{ this->func = func_; }
void call_func( ActionSwitchType type_ );
inline void clear_bitMap()noexcept{ bitMap.clear_all(); }
//-- 登记某个 actionSwitch --
inline void signUp( ActionSwitchType type_ )noexcept{
bitMap.signUp( static_cast<size_t>(type_) ); // can't use cast_2_siz_t
}
//-- 检查某个 actionSwitch 是否已登记 --
inline bool check( ActionSwitchType type_ )noexcept{
return bitMap.check( static_cast<size_t>(type_) ); // can't use cast_2_siz_t
}
private:
GameObj &goRef;
BoolBitMap bitMap {}; //- 位图,记录了本实例 注册了哪几个类型的 actionSwitch
//- 暂定上限为 64-bit
//--- functor ----//
F_ACTION_SWITCH func {nullptr};
};
#endif
|
turesnake/tprPixelGames | src/Engine/animFrameSet/AnimAction.h | <reponame>turesnake/tprPixelGames
/*
* ======================= AnimAction.h =====================
* -- tpr --
* CREATE -- 2019.05.06
* MODIFY --
* ----------------------------------------------------------
*/
#ifndef TPR_ANIM_ACTION_H
#define TPR_ANIM_ACTION_H
//=== *** glad FIRST, glfw SECEND *** ===
// Don't include glfw3.h ALONE!!!
#include<glad/glad.h>
#include<GLFW/glfw3.h>
#include "pch.h"
//-------------------- Engine --------------------//
#include "NineDirection.h"
#include "RGBA.h"
#include "AnimActionPos.h"
#include "functorTypes.h"
#include "BrokenLvl.h"
#include "AnimActionEName.h"
//-- need --//
class AnimFrameSet;
class AnimActionParam;
//-- 本class 只存储 于 anim-action 有关的 所有静态数据
// 纯粹的静态数据,不允许存储任何与 gomesh相关的动态数据 !!!!
// 动态数据 存储在 gomesh.animAction::PvtData 中 (每一个 gomesh 独占一份)
class AnimAction{
public:
//================== nested ================//
enum class PlayState{
Stop, // always for idle, and part of Once
Working // always for Cycle, and part of Once
};
// 动作播放类型
enum class PlayType{
Idle, //- 从来不更换 动画帧
Once, //- 只播放一次,支持 逻辑节点帧,结束后自动跳转到预定的 新状态(未定)
Cycle //- 循环播放一段 动画帧
};
static PlayType str_2_playType( const std::string &str_ )noexcept;
// gomesh 自己保存的 有关 animAction 的动态数据。
class PvtData{
public:
size_t currentIdx_for_frameIdxs {}; //- 当前真正播放的帧,在 frameIdxs 中的下标号
//---
size_t currentFrameIdx {}; //- 当前指向的 frameidx 值
size_t currentTimeStep {}; //- 当前帧的 timeStep, (不应被外部访问)
// 被 smoothDeltaTime 修正过
//---
size_t updates {}; //- 切换一次帧后,记录 调用 update() 的次数
//---
int timeStepOff {}; // 外界控制 aaction播放速度的 第一种方式
// 此值会被 累加在每一份 currentTimeStep 上,
//-- flags --//
PlayType playType {}; // copy from AnimAction.obj
PlayState playState {};
bool isLastFrame {false};//- Once: 播放进 最后一帧以及之后,永远处于 true
//- Cycle: 每一次播放到最后一帧,才为 true
//- Idle: always true
//========
// 实际上,由于动画中的每一图元帧,都会被播放好几 时间帧。
// 所有,isLastFrame 并不仅仅在 一个 时间帧 内被设置为 true
// 而是在 尾图元帧 播放的所有 时间帧里,被设置为 true
//--- functor ---//
F_R_double reset_playSpeedScale {nullptr}; // 外界控制 aaction播放速度的 第二种方式
};
//================== self ================//
AnimAction() = default;
void init( const AnimFrameSet &animFrameSetRef_,
const AnimActionParam ¶m_,
const AnimActionPos *animActionPosPtr_,
IntVec2 pixNum_per_frame_,
size_t headIdx_,
bool isHaveShadow_ );
std::function<void(AnimAction::PvtData &)> update {nullptr};
//- 当 gomesh 切换 animAction 时
// 通过此函数,来重置自己的 pvtdata 值 --
inline void reset_pvtData( AnimAction::PvtData &pvtData_ )noexcept{
pvtData_.currentIdx_for_frameIdxs = 0;
pvtData_.currentFrameIdx = this->frameIdxs.at(0);
pvtData_.currentTimeStep = this->timeSteps.at(0);
pvtData_.playType = this->actionPlayType;
switch (pvtData_.playType){
case PlayType::Idle:
pvtData_.playState = PlayState::Stop; // always
pvtData_.isLastFrame = true; // always
break;
case PlayType::Once:
pvtData_.playState = PlayState::Working;
pvtData_.isLastFrame = false;
break;
case PlayType::Cycle:
pvtData_.playState = PlayState::Working; // always
pvtData_.isLastFrame = false;
break;
default:
tprAssert(0);
break;
}
}
//----- get -----//
inline bool get_isHaveShadow() const noexcept{ return this->isHaveShadow; }
inline bool get_isOpaque() const noexcept{ return this->isOpaque; }
inline IntVec2 get_pixNum_per_frame() const noexcept{ return this->pixNum_per_frame; }
inline PlayType get_actionPlayType()const noexcept{ return this->actionPlayType; } // 将被废弃
inline const glm::dvec2 &get_currentRootAnchorDPosOff() const noexcept{
return this->animActionPosPtr->get_rootAnchorDPosOff();
}
inline GLuint get_currentTexName_pic( const AnimAction::PvtData &pvtData_ ) const noexcept{
return this->texNames_pic_ptr->at(pvtData_.currentFrameIdx);
}
inline GLuint get_currentTexName_shadow( const AnimAction::PvtData &pvtData_ ) const noexcept{
return this->texNames_shadow_ptr->at(pvtData_.currentFrameIdx);
}
inline const AnimActionPos &get_currentAnimActionPos() const noexcept{
return *this->animActionPosPtr;
}
private:
inline void update_idle( AnimAction::PvtData &pvtData_ ){ }
void update_once( AnimAction::PvtData &pvtData_ );
void update_cycle( AnimAction::PvtData &pvtData_ );
size_t adjust_currentTimeStep( size_t currentTimeStep_, AnimAction::PvtData &pvtData_ );
//===== vals =====//
//-- 从 animFrameSet 中获得的 只读指针 --
const std::vector<GLuint> *texNames_pic_ptr {nullptr};
const std::vector<GLuint> *texNames_shadow_ptr {nullptr};
const AnimActionPos *animActionPosPtr {nullptr}; // 1-animAction, 1-animActionPos
PlayType actionPlayType {};
//- 用户可以手动编排 frameIdx 序列。同时,默认 容器中的第一帧,就是 enterIdx --
std::vector<size_t> frameIdxs {}; //- 相对于 AnimFrameSet 全frames数据的 idx
std::vector<size_t> timeSteps {};
size_t totalFrameNum {}; //- 本 action 有几帧
IntVec2 pixNum_per_frame {}; //- 单帧画面 的 长宽 像素值
//===== flags =====//
bool isHaveShadow {};
bool isOpaque {};
};
//-- 作为 AnimFrameSet::insert_a_png() 参数 --
class AnimActionParam{
public:
//-- 常规构造器,且手动设置 timesteps --
AnimActionParam(size_t subspeciesIdx_,
AnimActionEName actionEName_,
NineDirection actionDir_,
BrokenLvl actionBrokenLvl_,
AnimAction::PlayType playType_,
bool isOrder_,
bool isOpaque_,
size_t jFrameIdx_,
const std::vector<size_t> &lFrameIdxs_,
const std::vector<size_t> &timeSteps_,
const std::string &label_ ):
subspeciesIdx(subspeciesIdx_),
actionEName(actionEName_),
actionDir(actionDir_),
actionBrokenLvl(actionBrokenLvl_),
actionPlayType( playType_ ),
isOrder( isOrder_ ),
isOpaque( isOpaque_ ),
isTimeStepsManualSet(true),
jFrameIdx(jFrameIdx_),
defaultTimeStep(6), //- 随便写一个值,反正用不上
animLabel(label_)
{
this->lFrameIdxs.insert( this->lFrameIdxs.end(), lFrameIdxs_.begin(), lFrameIdxs_.end() );
this->timeSteps.insert( this->timeSteps.end(), timeSteps_.begin(), timeSteps_.end() );
}
//-- 常规构造器,但使用统一值的 timesteps --
AnimActionParam(size_t subspeciesIdx_,
AnimActionEName actionEName_,
NineDirection actionDir_,
BrokenLvl actionBrokenLvl_,
AnimAction::PlayType playType_,
bool isOrder_,
bool isOpaque_,
size_t jFrameIdx_,
const std::vector<size_t> &lFrameIdxs_,
size_t _defaultTimeStep,
const std::string &label_ ):
subspeciesIdx(subspeciesIdx_),
actionEName(actionEName_),
actionDir(actionDir_),
actionBrokenLvl(actionBrokenLvl_),
actionPlayType( playType_ ),
isOrder( isOrder_ ),
isOpaque( isOpaque_ ),
isTimeStepsManualSet(false),
jFrameIdx(jFrameIdx_),
defaultTimeStep(_defaultTimeStep),
animLabel(label_)
{
this->lFrameIdxs.insert( this->lFrameIdxs.end(), lFrameIdxs_.begin(), lFrameIdxs_.end() );
this->timeSteps.push_back( _defaultTimeStep ); //- 用不上
}
//-- 单帧action 专用 构造器 --
AnimActionParam(size_t subspeciesIdx_,
AnimActionEName actionEName_,
NineDirection actionDir_,
BrokenLvl actionBrokenLvl_,
size_t jFrameIdx_,
size_t lFrameIdx_,
bool isOpaque_,
const std::string &label_ ):
subspeciesIdx(subspeciesIdx_),
actionEName(actionEName_),
actionDir(actionDir_),
actionBrokenLvl(actionBrokenLvl_),
actionPlayType( AnimAction::PlayType::Idle ), //- 默认type
isOrder( true ), //- 随便写一个值,反正用不上
isOpaque( isOpaque_ ),
isTimeStepsManualSet(false),
jFrameIdx(jFrameIdx_),
defaultTimeStep(6), //- 随便写一个值,反正用不上
animLabel(label_)
{
this->lFrameIdxs.push_back( lFrameIdx_ );
this->timeSteps.push_back( 6 ); //- 随便写一个值,反正用不上
}
//===== vals =====//
size_t subspeciesIdx;
AnimActionEName actionEName;
NineDirection actionDir;
BrokenLvl actionBrokenLvl;
AnimAction::PlayType actionPlayType;
bool isOrder;
bool isOpaque; //- 是否为 不透明图元
bool isTimeStepsManualSet; //- 若为 false,参数 timeSteps_ 可为空容器
size_t jFrameIdx; //- J帧序号,一个还在发展改善中的数值... 暂时手动设置
size_t defaultTimeStep; //- 若上参数为 false,通过本参数来设置 timeSteps
std::vector<size_t> lFrameIdxs {}; //- 和 AnimAction 中的 frameIdxs 不同,此处基于的idx 是相对值
std::vector<size_t> timeSteps {};
std::string animLabel {};
};
#endif
|
turesnake/tprPixelGames | src/Engine/resource/esrc_job_ecoObj.h | <filename>src/Engine/resource/esrc_job_ecoObj.h
/*
* ====================== esrc_job_ecoObj.h ==========================
* -- tpr --
* CREATE -- 2019.11.30
* MODIFY --
* ----------------------------------------------------------
*/
#ifndef TPR_ESRC_JOB_ECO_OBJ_H
#define TPR_ESRC_JOB_ECO_OBJ_H
//-------------------- Engine --------------------//
#include "sectionKey.h"
#include "EcoObj.h"
namespace esrc {//------------------ namespace: esrc -------------------------//
EcoObj &atom_insert_new_job_ecoObj( sectionKey_t ecoObjKey_ );
void atom_insert_2_job_ecoObjFlags( sectionKey_t ecoObjKey_ );
size_t atom_move_all_ecoObjUptrs_from_job_2_esrc();
}//---------------------- namespace: esrc -------------------------//
#endif
|
turesnake/tprPixelGames | src/Engine/renderPool/GroundRenderPool.h | /*
* ==================== GroundRenderPool.h ==========================
* -- tpr --
* CREATE -- 2019.09.28
* MODIFY --
* ----------------------------------------------------------
*/
#ifndef TPR_GROUND_RENDER_POOL_H
#define TPR_GROUND_RENDER_POOL_H
//-------------------- CPP --------------------//
#include <vector>
#include <map>
#include <unordered_set>
//-------------------- Engine --------------------//
#include "ChildMesh.h"
#include "Mesh.h"
#include "colorTableId.h"
class GroundRenderPool{
public:
GroundRenderPool()
{
this->init();
}
void init()noexcept;
inline void insert( colorTableId_t id_, float zOff_, ChildMesh *meshPtr_ )noexcept{
auto target = this->pools.find(id_);
tprAssert( target != this->pools.end() );
target->second.insert({ zOff_, meshPtr_ });// multi
}
inline void clear()noexcept{
for( auto &pair : this->pools ){
pair.second.clear();
}
}
void draw()noexcept;
private:
std::unordered_map<colorTableId_t, std::multimap<float, ChildMesh*>> pools {};
};
#endif
|
turesnake/tprPixelGames | src/Engine/shaderProgram/uniformBlockObjs.h | <reponame>turesnake/tprPixelGames
/*
* ===================== uniformBlockObjs.h ==========================
* -- tpr --
* CREATE -- 2019.09.22
* MODIFY --
* ----------------------------------------------------------
*/
#ifndef TPR_UNIFORM_BLOCK_OBJS_H
#define TPR_UNIFORM_BLOCK_OBJS_H
//=== *** glad FIRST, glfw SECEND *** ===
// Don't include glfw3.h ALONE!!!
#include<glad/glad.h>
//-------------------- CPP --------------------//
#include <unordered_map>
//-------------------- Engine --------------------//
#include "UniformBlockObj.h"
#include "FloatVec.h"
namespace ubo{//------------- namespace ubo ----------------
// 1-ubo_instance, 1 enum-obj
enum class UBOType{
Seeds,
Camera,
Window,
Time,
WorldCoord,
OriginColorTable,
UnifiedColorTable,
GroundColorTable,
ColorTableId,
//...
BioSoupColorTable,
};
inline std::unordered_map<UBOType, GLuint> uboBindPoints {
{UBOType::Seeds, 1 },
{UBOType::Camera, 2 },
{UBOType::Window, 3 },
{UBOType::Time, 4 },
{UBOType::WorldCoord, 5 },
{UBOType::OriginColorTable, 6 },
{UBOType::UnifiedColorTable, 7 },
{UBOType::GroundColorTable, 8 },
{UBOType::ColorTableId, 9 },
{UBOType::BioSoupColorTable, 10 }
//...
};
inline GLuint get_bindPoint( UBOType type_ )noexcept{
tprAssert( uboBindPoints.find(type_) != uboBindPoints.end() );
return uboBindPoints.at(type_);
}
}//------------- namespace ubo: end ----------------
#endif
|
turesnake/tprPixelGames | src/Engine/collision/ColliderType.h | /*
* ====================== ColliderType.h ==========================
* -- tpr --
* CREATE -- 2019.09.01
* MODIFY --
* ----------------------------------------------------------
*/
#ifndef TPR_COLLIDER_TYPE_H
#define TPR_COLLIDER_TYPE_H
#include "pch.h"
enum class ColliderType{
Nil,
//---
Circular, // 最全最复杂的 碰撞体,所有 活体go。只能用此类型
// 参与 moveCollide, 也参与 skillCollide
// 唯一可以 移动 的类型,
// 拥有自定义 碰撞圆半径,以便别的go,碰到它
// 当扮演 dogo 时,则使用一个统一的 标准半径值
// 每次移动,都需要及时更新自己的 mapent 登记信息
Square, // 专用于 静态地景go。
// 参与 moveCollide, 不参与 skillCollide
// 无法移动,碰撞区就是一个 完整的 mapent
Arc, // 参与 skillCollide,
// 可以移动,但不参与 moveCollide
// 不会被登记到 mapent 上
};
ColliderType str_2_colliderType( const std::string &name_ )noexcept;
enum class CollideState{
Separate, //- 相离
Adjacent, //- 相临 (会出发滑动效果)
Intersect, //- 相交
};
enum class CollideFamily{
Move,
Skill,
};
class Circular{
public:
Circular() = default;
Circular( const glm::dvec2 &dpos_, double radius_ ):
dpos(dpos_),
radius(radius_)
{}
inline Circular calc_new_circular( const glm::dvec2 &dposOff_ ) const noexcept{
return Circular{ this->dpos+dposOff_, this->radius };
}
//----- vals -----//
glm::dvec2 dpos {};
double radius {};
//----- static -----//
static double radius_for_dogo; // 扮演 dogo 时,使用一个标准值 24.0
};
class ArcLine{
public:
ArcLine()=default;
ArcLine(const glm::dvec2 &dpos_,
const glm::dvec2 &forward_,
double radius_,
double halfRadian_):
dpos(dpos_),
forward(forward_),
radius(radius_),
halfRadian(halfRadian_)
{}
//----- vals -----//
glm::dvec2 dpos {};
glm::dvec2 forward {};
double radius {};
double halfRadian {};// 半弧
};
class Square{
public:
Square()=default;
explicit Square( const glm::dvec2 &dpos_):
dpos(dpos_),
radius( Square::unifiedRadius )
{}
//----- vals -----//
glm::dvec2 dpos {};
double radius {}; // 未来可以被取消 ...
//----- static -----//
static double unifiedRadius; // 唯一且统一的半径值
};
#endif
|
turesnake/tprPixelGames | src/Engine/tprDebug/speedLog.h | /*
* ======================== speedLog.h ==========================
* -- tpr --
* CREATE -- 2019.10.05
* MODIFY --
* ----------------------------------------------------------
*/
#ifndef TPR_SPEED_LOG_H
#define TPR_SPEED_LOG_H
//--- glm - 0.9.9.5 ---
#include "glm_no_warnings.h"
namespace tprDebug {//---------- namespace: tprDebug --------------//
void init_speedLog();
void collect_playerSpeed( const glm::dvec2 &speedV_ );
void process_and_echo_speedLog();
void collect_cameraSpeed( const glm::dvec2 &speedV_ );
}//-------------------- namespace: tprDebug end --------------//
#endif
|
turesnake/tprPixelGames | src/Engine/mesh/RotateScaleData.h | <reponame>turesnake/tprPixelGames
/*
* ================== RotateScaleData.h ==========================
* -- tpr --
* CREATE -- 2019.08.21
* MODIFY --
* ----------------------------------------------------------
*/
#ifndef TPR_CHILD_MESH_ROTATE_DATA_H
#define TPR_CHILD_MESH_ROTATE_DATA_H
//--- glm - 0.9.9.5 ---
#include "glm_no_warnings.h"
//-------------------- CPP --------------------//
#include <vector>
#include <utility> // move
//-------------------- Engine --------------------//
//- 暂时只支持 xyz 三个轴线的旋转
enum class RotateType{
X,
Y,
Z
};
// 外部向 GoMesh 传入的 rotate/scale 数据
class RotateScaleData{
public:
RotateScaleData() = default;
//--- set ---//
inline void reset_rotateOrder( std::vector<RotateType> order_ )noexcept{
this->rotateOrder.swap( order_ );
}
inline void set_rotateDegree( const glm::vec3 &rad_ )noexcept{
this->rotateDegree = rad_;
}
inline void set_scale( const glm::vec2 &scale_ )noexcept{
this->scale = scale_;
}
//--- get ---//
inline const glm::vec3 &get_rotateDegreeRef() const noexcept{
return this->rotateDegree;
}
inline const glm::vec2 &get_scaleRef() const noexcept{
return this->scale;
}
inline bool isNeedToRotate() const noexcept{
return !rotateOrder.empty();
}
inline const std::vector<RotateType> &get_rotateOrder() const noexcept{
return this->rotateOrder;
}
private:
//- 一个不是很完善的解决方案:
// 依次向 rotateOrder 压入 x/y/z,每一种只能压入一次,次序不限
// 实际旋转时,按照 这个 vector 中的次序依次旋转
// ---
// 如果 rotateOrder 为空,就说明不需要旋转
std::vector<RotateType> rotateOrder {};
glm::vec3 rotateDegree {glm::vec3(0.0f, 0.0f, 0.0f)}; //- Degree [0.0f, 360.0f]
glm::vec2 scale {glm::vec2(1.0f, 1.0f)}; // 仅仅是 外部希望的 缩放比例
// 不是最终算进 mat4 的值
};
#endif
|
turesnake/tprPixelGames | src/Engine/blueprint/BlueprintVarType.h | /*
* ======================= BlueprintVarType.h =======================
* -- tpr --
* CREATE -- 2019.12.02
* MODIFY --
* ----------------------------------------------------------
*/
#ifndef TPR_BLUE_PRINT_VARIABLE_H
#define TPR_BLUE_PRINT_VARIABLE_H
#include "pch.h"
//-------------------- Engine --------------------//
#include "RGBA.h"
namespace blueprint {//------------------ namespace: blueprint start ---------------------//
//-- 蓝图专用 变量
// 每种变量,在png数据中,以一种固定的颜色来表达
//
enum class VariableTypeIdx{
V_1,
V_2,
V_3,
V_4,
V_5,
V_6,
V_7,
V_8,
V_9,
V_10,
V_11,
V_12,
V_13,
V_14,
V_15,
V_16,
V_17,
V_18,
V_19,
V_20,
V_21,
V_22,
V_23,
V_24,
V_25,
V_26,
V_27,
V_28,
V_29,
V_30
//...
};
std::optional<VariableTypeIdx> rgba_2_VariableTypeIdx( RGBA rgba_ )noexcept;
VariableTypeIdx str_2_variableTypeIdx( const std::string &name_ )noexcept;
}//--------------------- namespace: blueprint end ------------------------//
#endif
|
turesnake/tprPixelGames | src/Engine/gameObj/DiskGameObj.h | /*
* ===================== DiskGameObj.h ==========================
* -- tpr --
* CREATE -- 2019.05.02
* MODIFY --
* ----------------------------------------------------------
* GameObj 各种数据 结构
* ----------------------------
*/
#ifndef TPR_DISK_GAME_OBJ_H
#define TPR_DISK_GAME_OBJ_H
//--- glm - 0.9.9.5 ---
#include "glm_no_warnings.h"
//------------------- Engine --------------------//
#include "IntVec.h"
#include "GameObjType.h"
#include "goLabelId.h"
#include "NineDirection.h"
#include "BrokenLvl.h"
class DiskGameObj{
public:
goid_t goid {}; //- u64
goSpeciesId_t goSpeciesId {}; //- u32
goLabelId_t goLabelId {}; // u64
glm::dvec2 dpos {}; //- double, double
size_t goUWeight {}; // u64
NineDirection dir {}; // int
BrokenLvl brokenLvl {}; // int
};
#endif
|
turesnake/tprPixelGames | deps/glm.9.9.5/glm_no_warnings.h | <reponame>turesnake/tprPixelGames
/*
* ===================== glm_no_warnings.h =================
* -- tpr --
* CREATE -- 2019.06.08
* MODIFY --
* ----------------------------------------------------------
*/
#ifndef TPR_GLM_NO_WARNINGS_H_
#define TPR_GLM_NO_WARNINGS_H_
//-- 屏蔽掉 glm 中的所有 warnings --
#pragma clang system_header
//--- glm - 0.9.9.5 ---
#include <glm_inn/glm.hpp>
//-- glm::vec3
//-- glm::vec4
//-- glm::mat4
#include <glm_inn/gtc/matrix_transform.hpp>
//-- glm::translate
//-- glm::rotate
//-- glm::scale
//-- glm::perspective
#include <glm_inn/gtc/type_ptr.hpp>
//-- glm::value_ptr
//-------------------- C --------------------//
#include <cmath>
inline glm::dvec2 glm_vec2_2_dvec2( const glm::vec2 &fv_ ){
return glm::dvec2{ static_cast<double>(fv_.x),
static_cast<double>(fv_.y) };
}
inline glm::vec2 glm_dvec2_2_vec2( const glm::dvec2 &dv_ ){
return glm::vec2{ static_cast<float>(dv_.x),
static_cast<float>(dv_.y) };
}
inline glm::dvec3 glm_vec3_2_dvec3( const glm::vec3 &fv_ ){
return glm::dvec3{ static_cast<double>(fv_.x),
static_cast<double>(fv_.y),
static_cast<double>(fv_.z) };
}
inline glm::vec3 glm_dvec3_2_vec3( const glm::dvec3 &dv_ ){
return glm::vec3{ static_cast<float>(dv_.x),
static_cast<float>(dv_.y),
static_cast<float>(dv_.z) };
}
#endif
|
turesnake/tprPixelGames | src/Engine/time/TimeBase.h | <reponame>turesnake/tprPixelGames<gh_stars>100-1000
/*
* ========================= TimeBase.h ==========================
* -- tpr --
* CREATE -- 2018.12.22
* MODIFY --
* ----------------------------------------------------------
* 基础时间类
* ----------------------------
*/
#ifndef TPR_TIME_BASE_H
#define TPR_TIME_BASE_H
//=== *** glad FIRST, glfw SECEND *** ===
// Don't include glfw3.h ALONE!!!
#include<glad/glad.h>
#include<GLFW/glfw3.h>
//------------------- CPP --------------------//
#include <cmath>
#include <functional>
#include <vector>
//------------------- Engine --------------------//
#include "timeLog.h"
#include "functorTypes.h"
//--- 最基础的时间类,singleton ---//
class TimeBase{
public:
TimeBase()=default;
//--- 在 每一主循环 起始处调用 ---//
inline void update_before_all()noexcept{
this->frameNum++;
this->currentTime = glfwGetTime();
this->deltaTime = this->currentTime - this->lastTime; //-- 更新 deltaTime
this->lastTime = this->currentTime;
//---- smoothDeltaTime ----//
//-- 游戏启动后,前10帧 不平滑 dt值 --
if( this->frameNum < 10 ){
this->smoothDeltaTime = this->deltaTime;
return;
}
//-- 游戏正常后,开始 平滑 dt值 --
double off = this->deltaTime - this->smoothDeltaTime;
if( std::abs(off) <= this->step ){
//-- 波动不大,直接对齐 --
this->smoothDeltaTime = this->deltaTime;
}else{
//-- 波动过大,步进对齐 --
(off > 0) ? this->smoothDeltaTime += this->step :
this->smoothDeltaTime -= this->step;
}
//--- windClock ---
for( auto &f : this->updates ){
f();
}
//-----------
tprDebug::collect_deltaTime(this->deltaTime); //- debug
}
inline void insert_update_functor( F_void update_ ){
this->updates.push_back( update_ );
}
//--- 获得 当前时间 (从 glfw 启动 开始计算)---//
// 目前仅被用于 random.cpp -> get_new_seed()
inline double get_currentTime()noexcept{ return glfwGetTime(); }
//--- 获得 上一帧的 deltaTime ---//
// ...目前未被任何代码使用...
inline double get_last_deltaTime() const noexcept{ return this->deltaTime; }
//--- 获得 平滑处理过的 deltaTime ---//
// 注意,此处的 deltaTime 不是 “上一帧的 dt”,
// 而是一个 平滑值。专门提供给 其它 模块使用
// ...目前未被任何代码使用...
inline double get_smoothDeltaTime() const noexcept{ return this->smoothDeltaTime; }
inline uint64_t get_frameNum()const noexcept{ return this->frameNum; } //-- 获得 游戏 总帧数 --//
//-- 依靠 db记录的 gameTime 旧值,来重启 gameTime 记录器 --
inline void start_record_gameTime( double gameTime_from_db_ )noexcept{
this->lastGameTime_from_db = gameTime_from_db_;
this->begPoint_of_gameTime = this->currentTime;
}
//-- 获得当前时刻的 gameTime 值 --
// 此函数可在 游戏运行期 的任何时刻 调用
inline double get_gameTime() const noexcept{
return (this->currentTime - this->begPoint_of_gameTime +
this->lastGameTime_from_db );
}
//===== static =====//
static double logicUpdateTimeLimit;
private:
std::vector<F_void> updates {}; // oth mods
//----- vals -----//
uint64_t frameNum {0}; //- 游戏运行后的 总帧数
//-- deltaTime --
double currentTime {0.0}; //-- 当前 时间值
double lastTime {0.0}; //-- 上一帧的 时间值
double deltaTime {0.0}; //-- 当前帧 与 上一帧的 时间差
//-- smoothDeltaTime --
double smoothDeltaTime {0.0}; //-- 平滑处理过的 dt值。专用于其他模块
double step {0.001}; //- 平滑 步进值
//-- gameTime --
// gameTime : 游戏运行总时间
// 这个值并不真的存储,而是每次 读取时(get) 临时计算一个。
double lastGameTime_from_db {0.0}; //- 从db读取的,gameTime 值
double begPoint_of_gameTime {0.0}; //- 当玩家选中一个存档时,会记下此时的 currentTime
//- 作为 本局游戏的 gameTime 起始值
};
inline double TimeBase::logicUpdateTimeLimit {1.0/60.0};
#endif
|
turesnake/tprPixelGames | src/Engine/resource/esrc_VAOVBO.h | /*
* ======================= esrc_VAOVBO.h ==========================
* -- tpr --
* CREATE -- 2018.12.24
* MODIFY --
* ----------------------------------------------------------
* 本游戏只有一份 VAO,VBO。
* 所有的 mesh/goMesh 都应该包含 本文件,直接使用里面的 VAO,VBO
* ----------------------------
*/
#ifndef TPR_ESRC_VAO_VBO_H
#define TPR_ESRC_VAO_VBO_H
//=== *** glad FIRST, glfw SECEND *** ===
// Don't include glfw3.h ALONE!!!
#include <glad/glad.h>
//-------------------- CPP --------------------//
#include <vector>
#include <utility>
//-------------------- Engine --------------------//
#include "VAOVBO.h"
namespace esrc {//------------------ namespace: esrc -------------------------//
void init_VAOVBO();
void delete_VAOVBO()noexcept;
GLuint get_VAO()noexcept;
GLsizei get_pointNums()noexcept;
}//---------------------- namespace: esrc -------------------------//
#endif
|
turesnake/tprPixelGames | src/Engine/blueprint/blueprint_oth.h | /*
* ===================== blueprint_oth.h =======================
* -- tpr --
* CREATE -- 2019.12.02
* MODIFY --
* ----------------------------------------------------------
*/
#ifndef TPR_BLUE_PRINT_OTH_H
#define TPR_BLUE_PRINT_OTH_H
#include "pch.h"
//-------------------- Engine --------------------//
#include "blueprintId.h"
#include "GameObjType.h"
#include "NineDirection.h"
#include "BrokenLvl.h"
namespace blueprint {//------------------ namespace: blueprint start ---------------------//
enum class BlueprintType{
Plot,
Yard,
Village
};
// 为了简化实现,yard 强制规定,必须为 正方形,
// 且必须对其与 field
enum class YardSize{
_1f1 = 1,
_2f2 = 2,
_3f3 = 3,
_4f4 = 4,
_5f5 = 5,
_6f6 = 6,
};
inline YardSize sizeByMapEnt_2_yardSize( IntVec2 size_ )noexcept{
tprAssert( (size_.x == size_.y) &&
(size_.x > 0) &&
((size_.x % ENTS_PER_FIELD<>) == 0) );
switch ( size_.x / ENTS_PER_FIELD<> ){
case 1: return YardSize::_1f1;
case 2: return YardSize::_2f2;
case 3: return YardSize::_3f3;
case 4: return YardSize::_4f4;
case 5: return YardSize::_5f5;
case 6: return YardSize::_6f6;
default:
tprAssert(0); // 值太大了,暂未支持
return YardSize::_6f6; // never reach
}
}
//-- 获得不同尺寸的 yard 的边长 (以 mapent 为单位)
inline int yardSize_2_mapEnt_sideLen( YardSize type_ )noexcept{
return static_cast<int>(type_) * ENTS_PER_FIELD<>;
}
IntVec2 parse_png_for_plot( std::vector<MapData> &mapDatasRef_,
const std::string &pngPath_M_,
IntVec2 frameNum_,
size_t totalFrameNum_ );
class YardBlueprint;
IntVec2 parse_png_for_yard( YardBlueprint &yardRef_,
const std::string &pngPath_M_,
const std::vector<size_t> &frameAllocateTimes_,
IntVec2 frameNum_,
size_t totalFrameNum_,
size_t fstFrameIdx_,
size_t frameNums_ );
IntVec2 parse_png_for_village( std::vector<MapData> &mapDatasRef_,
const std::string &pngPath_M_,
IntVec2 frameNum_,
size_t totalFrameNum_,
bool isHaveRoad );
// "" / "Default", 将被统一替换为 "DEFAULT"
// 以此来表示,一种 默认 label
// 不考虑 运行性能
inline std::string check_and_unify_default_labels( const std::string &label_ )noexcept{
if( (label_=="") ||
(label_=="default") ||
(label_=="Default") ||
(label_=="DEFAULT") ){
return "_DEFAULT_";
}else{
return label_; // copy,无需考虑性能
}
}
}//--------------------- namespace: blueprint end ------------------------//
#endif
|
turesnake/tprPixelGames | src/Engine/gameObj/GameObjPos.h | /*
* ========================= GameObjPos.h ==========================
* -- tpr --
* CREATE -- 2019.01.20
* MODIFY --
* ----------------------------------------------------------
*/
#ifndef TPR_GAME_OBJ_POS_H
#define TPR_GAME_OBJ_POS_H
#include "pch.h"
//-------------------- CPP --------------------//
#include <utility> // pair
//-------------------- Engine --------------------//
#include "MapCoord.h"
#include "GoAltiRange.h"
//-- based on go.rootAnchor
class GameObjPos{
public:
GameObjPos() = default;
inline void init( const glm::dvec2 &dpos_ )noexcept{
this->currentDPos = dpos_;
}
//------- set -------//
inline void set_alti( double alti_ )noexcept{ this->alti = alti_; }
inline void set_lAltiRange ( GoAltiRange new_ )noexcept{ this->lAltiRange = new_; }
inline void accum_dpos( const glm::dvec2 &addDPos_ )noexcept{ this->currentDPos += addDPos_; }
//------- get -------//
inline const glm::dvec2 &get_dpos()const noexcept{ return this->currentDPos; }
inline double get_alti()const noexcept{ return this->alti; }
inline GoAltiRange get_lAltiRange()const noexcept{ return this->lAltiRange; }
private:
glm::dvec2 currentDPos {}; // rootAnchor 本点 当前dpos,(无需对齐与mapent)
double alti {0.0}; //- 腾空高度。
GoAltiRange lAltiRange {}; // 碰撞体 高度区间
};
#endif
|
turesnake/tprPixelGames | src/Engine/resource/esrc_colorTableSet.h | <reponame>turesnake/tprPixelGames
/*
* ==================== esrc_colorTableSet.h ==========================
* -- tpr --
* CREATE -- 2019.09.23
* MODIFY --
* ----------------------------------------------------------
*/
#ifndef TPR_ESRC_COLOR_TABLE_SET_H
#define TPR_ESRC_COLOR_TABLE_SET_H
//-------------------- Engine --------------------//
#include "ColorTable.h"
namespace esrc {//------------------ namespace: esrc -------------------------//
void init_colorTableSet()noexcept;
ColorTableSet &get_colorTabelSet()noexcept;
CurrentColorTable &get_currentColorTabel()noexcept;
void rebind_currentColorTabel_target( colorTableId_t id_ )noexcept;
}//---------------------- namespace: esrc -------------------------//
#endif
|
turesnake/tprPixelGames | src/Engine/map/sectionKey.h | <filename>src/Engine/map/sectionKey.h
/*
* ====================== sectionKey.h =======================
* -- tpr --
* CREATE -- 2019.01.07
* MODIFY --
* ----------------------------------------------------------
* section "id": (int)w + (int)h
* ----------------------------
*/
#ifndef TPR_SECTION_KEY_H
#define TPR_SECTION_KEY_H
//-------------------- CPP --------------------//
#include <vector>
//-------------------- Engine --------------------//
#include "tprAssert.h"
#include "config.h"
#include "IntVec.h"
#include "MapCoord.h"
using sectionKey_t = uint64_t;
sectionKey_t sectionMPos_2_key_inn( IntVec2 sectionMPos_ )noexcept; //- 不推荐外部代码使用
IntVec2 sectionKey_2_mpos( sectionKey_t key_ )noexcept;
IntVec2 anyMPos_2_sectionMPos( IntVec2 mpos_ )noexcept;
IntVec2 get_section_lMPosOff( IntVec2 anyMPos_ )noexcept;
sectionKey_t anyMPos_2_sectionKey( IntVec2 anyMPos_ )noexcept;
sectionKey_t sectionMPos_2_sectionKey( IntVec2 sectionMPos_ )noexcept;
/* ===========================================================
* sectionMPos_2_key_inn
* -----------------------------------------------------------
* -- 传入 section左下角mpos,获得 section key(u64)
* param: sectionMPos_ - 必须为 section左下角mpos。
*/
inline sectionKey_t sectionMPos_2_key_inn( IntVec2 sectionMPos_ )noexcept{
sectionKey_t key {};
int *ptr = (int*)&key;
*ptr = sectionMPos_.x;
ptr++;
*ptr = sectionMPos_.y;
//--------
return key;
}
/* ===========================================================
* sectionKey_2_mpos
* -----------------------------------------------------------
* -- 传入某个key,生成其 section 的 mpos
*/
inline IntVec2 sectionKey_2_mpos( sectionKey_t key_ )noexcept{
IntVec2 mpos {};
int *ptr = (int*)&key_;
//---
mpos.x = *ptr;
ptr++;
mpos.y = *ptr;
//---
return mpos;
}
/* ===========================================================
* anyMPos_2_sectionMPos
* -----------------------------------------------------------
* -- 传入 任意 mapent 的 mpos,获得其 所在 section 的 mpos(section左下角)
*/
inline IntVec2 anyMPos_2_sectionMPos( IntVec2 anyMPos_ )noexcept{
return ( floorDiv(anyMPos_, ENTS_PER_SECTION_D) * ENTS_PER_SECTION<> );
}
/* ===========================================================
* get_section_lMPosOff
* -----------------------------------------------------------
* -- 获得 目标mapent.mpos 在其 section 中的 相对mpos偏移
*/
inline IntVec2 get_section_lMPosOff( IntVec2 anyMPos_ )noexcept{
return ( anyMPos_ - anyMPos_2_sectionMPos(anyMPos_) );
}
/* ===========================================================
* anyMPos_2_sectionKey
* -----------------------------------------------------------
* -- 当需要通过 mpos 计算出它的 key,又不需要 正式制作一个 SectionKey实例时,
* 推荐使用本函数。
* -- 这个函数会使得调用者代码 隐藏一些bug。
* 在明确自己传入的参数就是 sectionMPos 时,推荐使用 sectionMPos_2_sectionKey()
* param: anyMPos_ -- 任意 mapent 的 mpos
*/
inline sectionKey_t anyMPos_2_sectionKey( IntVec2 anyMPos_ )noexcept{
IntVec2 sectionMPos = anyMPos_2_sectionMPos( anyMPos_ );
return sectionMPos_2_key_inn( sectionMPos );
}
/* ===========================================================
* sectionMPos_2_sectionKey
* -----------------------------------------------------------
* -- 当使用者 确定自己传入的参数就是 sectionMPos, 使用此函数
* 如果参数不为 sectionMPos,直接报错。
*/
inline sectionKey_t sectionMPos_2_sectionKey( IntVec2 sectionMPos_ )noexcept{
tprAssert( anyMPos_2_sectionMPos(sectionMPos_) == sectionMPos_ ); //- tmp
return sectionMPos_2_key_inn( sectionMPos_ );
}
#endif
|
turesnake/tprPixelGames | src/Engine/scene/sceneLoop.h | <gh_stars>100-1000
/*
* ====================== sceneLoop.h =======================
* -- tpr --
* CREATE -- 2019.04.29
* MODIFY --
* ----------------------------------------------------------
*/
#ifndef TPR_SCENE_LOOP_H
#define TPR_SCENE_LOOP_H
//-------------------- CPP --------------------//
#include <functional>
//-------------------- Engine --------------------//
#include "functorTypes.h"
enum class SceneLoopType : int{
Null,
//FirstPlayInputSet, //- 第一次启动游戏时,强制进入 按键设置界面
Begin, //- 最最基础的 游戏启动界面
World //- 主游戏
};
inline F_void sceneRenderLoopFunc {nullptr};
inline F_void sceneLogicLoopFunc {nullptr};
//void prepareForScene_firstPlayInputSet();
void prepareForScene_begin();
void prepareForScene_world();
void switch_sceneLoop( SceneLoopType type_ );
#endif
|
turesnake/tprPixelGames | src/Engine/resource/esrc_gameObj.h |
/*
* ========================= esrc_gameObj.h ==========================
* -- tpr --
* CREATE -- 2019.04.19
* MODIFY --
* ----------------------------------------------------------
*/
#ifndef TPR_ESRC_GAME_OBJ_H
#define TPR_ESRC_GAME_OBJ_H
//-------------------- CPP --------------------//
#include <string>
#include <functional>
#include <optional>
#include <unordered_map>
#include <unordered_set>
//-------------------- Engine --------------------//
#include "GameObj.h"
namespace esrc {//------------------ namespace: esrc -------------------------//
void init_gameObjs();
void debug_for_gameObjs()noexcept;
std::unordered_set<goid_t> &get_goids_active();
std::unordered_set<goid_t> &get_goids_inactive();
void insert_2_goids_active( goid_t id_ );
void insert_2_goids_inactive( goid_t id_ );
std::optional<GameObj*> get_goPtr( goid_t id_ )noexcept;
//GameObj *get_goRawPtr( goid_t id_ );
bool is_go_active(goid_t id_ ); //- tmp
using F_GOID_GOPTR = std::function<void(goid_t, GameObj&)>;
void foreach_goids_active( F_GOID_GOPTR fp_ );
void foreach_goids_inactive( F_GOID_GOPTR fp_ );
goid_t insert_new_regularGo( const glm::dvec2 &dpos_, size_t goUWeight_ );
goid_t insert_new_uiGo( const glm::dvec2 &basePointProportion_, const glm::dvec2 &offDPos_, size_t goUWeight_ );
void insert_a_diskGo( goid_t goid_, const glm::dvec2 &dpos_, size_t goUWeight_ );
void erase_the_go( goid_t id_ );
void realloc_active_goes();
void realloc_inactive_goes();
void refresh_worldUIGo_chunkSignUpData( GameObj &goRef_, const glm::dvec2 &moveVec_ );
}//---------------------- namespace: esrc -------------------------//
#endif
|
turesnake/tprPixelGames | src/Engine/circuitBoard/CircuitBoard.h | /*
* ====================== CircuitBoard.h ==========================
* -- tpr --
* CREATE -- 2020.01.04
* MODIFY --
* ----------------------------------------------------------
*/
#ifndef TPR_CIRCUIT_BOARD_H
#define TPR_CIRCUIT_BOARD_H
#include "pch.h"
//------------------- Engine --------------------//
#include "GameObjType.h"
#include "mapEntKey.h"
/* "电路板"系统
* 所有 artifact-go/mpgo 实例,可在自己被创建之时,在 "电路板"系统中,
* 在自身附近的某些 mapent位置上,留一组函数
* 当目标 mapent 在未来出生一个 mpgo 时,此mpgo 会自动拾取 之前登记的这组函数,并在条件符合时执行它
* === 数据的卸载
* 唯独当 数据的登记者 dogo 被释放时,才会将与dogo 关联的所有 数据,逐个删除(最耗时,但干净的办法)
* === 登记函数的作用周期
* -1- 只要 登记者/dogo 存在,与它关联的 登记函数会始终存在。
* 哪怕 目标 mapent 所属的 chunk 已经被释放了
*
* 一个 dogo,只能登记一份 functor。
* 若存在细分需求,则要在 这个函数 体内完成
*
* ====== 用法 =======
* 由于 关联只发送在 mpgo 被创建的一瞬间,所以,登记的函数,最常用来实现的功能,就是 连接数个 mpgo 之间的父子关系
*/
class CircuitBoard{
public:
//================== nested ==================//
// 调用优先级
enum class MessageWeight{
V_0 = 0, // last call
V_1,
V_2,
V_3,
V_4,
V_5, // first call
};
private:
// 当一个 dogo 被释放时,会直接释放 dogoids容器中 所有关联数据 (最彻底的做法)
// 同时,若发现 dogoids 已为空,将直接删除 本 mapEntMessage 实例
class MapEntMessage{
public:
MapEntMessage()=default;
std::multimap<MessageWeight, goid_t> dogoids {};
};
public:
//================== static ==================//
static void init_for_static()noexcept;// MUST CALL IN MAIN !!!
static void signUp( goid_t dogoid_, F_AFFECT functor_,
const std::map<mapEntKey_t, CircuitBoard::MessageWeight> &mpDatas_ )noexcept;
static void check_and_call_messages( IntVec2 mpos_, GameObj &begoRef_ )noexcept;
static void erase_dogoMessages( goid_t dogoid_, const std::map<mapEntKey_t, CircuitBoard::MessageWeight> &mpDatas_ )noexcept;
private:
static std::unordered_map<mapEntKey_t, std::unique_ptr<MapEntMessage>> messages;
static std::unordered_map<goid_t, F_AFFECT> functors; // 实际 函数对象 存储地
};
#endif
|
turesnake/tprPixelGames | src/Engine/resource/esrc_ecoObj.h | <filename>src/Engine/resource/esrc_ecoObj.h
/*
* ========================= esrc_ecoObj.h ==========================
* -- tpr --
* CREATE -- 2019.04.19
* MODIFY --
* ----------------------------------------------------------
*/
#ifndef TPR_ESRC_ECO_OBJ_H
#define TPR_ESRC_ECO_OBJ_H
//-------------------- CPP --------------------//
#include <unordered_map>
#include <utility> //- pair
#include <memory>
//-------------------- Engine --------------------//
#include "EcoObj.h"
#include "IntVec.h"
#include "sectionKey.h"
#include "EcoObj_ReadOnly.h"
#include "GoSpecData.h"
#include "esrc_ecoObjMemState.h"
namespace esrc {//------------------ namespace: esrc -------------------------//
void init_ecoObjs()noexcept;
void moveIn_ecoObjUPtr_from_job( sectionKey_t ecoObjKey_, std::unique_ptr<EcoObj> ecoObjUPtr_ );
void del_ecoObjs_tooFarAway()noexcept;
//-- 更加精细的 元素数据 只读访问 接口 [值传递] --
std::unique_ptr<EcoObj_ReadOnly> get_ecoObj_readOnly( sectionKey_t sectionkey_ )noexcept;
EcoObj &get_ecoObjRef( sectionKey_t sectionkey_ )noexcept;
}//---------------------- namespace: esrc -------------------------//
#endif
|
turesnake/tprPixelGames | src/Engine/input/InputINS.h | <reponame>turesnake/tprPixelGames
/*
* ========================= InputINS.h ==========================
* -- tpr --
* CREATE -- 2019.02.13
* MODIFY --
* ----------------------------------------------------------
* 游戏按键指令
* -----
* 物理鼠键 -> inputINS
* ----------------------------
*/
#ifndef TPR_INPUT_INS_H
#define TPR_INPUT_INS_H
//--- glm - 0.9.9.5 ---
#include "glm_no_warnings.h"
//------------------- CPP --------------------//
#include <cstdint> // uint8_t
//-------------------- Engine --------------------//
#include "tprAssert.h"
#include "GameKey.h"
#include "DirAxes.h"
//-- 存储 游戏识别的所有 按键信息,
// 但这里的 按键并不需要全部传输给 go,
// 比如 “打开状态面板” 这种按键,就会被 分发给对应的模块
//-- 不应将 此数据 直接传递给 go,而应该转换为 游戏动作指令
class InputINS{
public:
//-- 并不清空 dir --
inline void clear_allKeys()noexcept{
this->keys = 0;
this->dirAxes.clear_all();
}
inline void set_key( GameKey key_ )noexcept{
keys = keys | (1<<static_cast<int>(key_));
}
inline void collect_dirAxes_from_joystick( const glm::dvec2 &val_ )noexcept{
//this->dirAxes.set( val_ );
this->dirAxes = DirAxes{ val_ };
}
inline bool get_key( GameKey key_ )const noexcept{
int idx = static_cast<int>(key_);
return ( ((keys>>idx) & 1) == 1 );
}
inline const DirAxes &get_dirAxes()const noexcept{
return this->dirAxes;
}
inline bool is_dir_up()const noexcept{
return (this->dirAxes.get_originVal().y > 0.7);
}
inline bool is_dir_down()const noexcept{
return (this->dirAxes.get_originVal().y < -0.7);
}
inline bool is_dir_left()const noexcept{
return (this->dirAxes.get_originVal().x < -0.7);
}
inline bool is_dir_right()const noexcept{
return (this->dirAxes.get_originVal().x > 0.7);
}
private:
//======== vals ========//
uint32_t keys {0}; //- 15个功能按键, bit-map, 实际可存储 32 个
DirAxes dirAxes {}; //- 方向键数据 [-1.0, 1.0]
};
#endif
|
turesnake/tprPixelGames | src/Engine/multiThread/Job.h | /*
* ========================== Job.h =======================
* -- tpr --
* CREATE -- 2019.04.24
* MODIFY --
* ----------------------------------------------------------
* 将任务封装成不同的 job,发送给 job线程
* ----------------------------
*/
#ifndef TPR_JOB_H
#define TPR_JOB_H
//-------------------- CPP --------------------//
#include <vector>
#include <any>
//-------------------- Engine --------------------//
#include "JobType.h"
#include "tprAssert.h"
class Job{
public:
template<typename T>
inline T *init_param()noexcept{
this->param = T {};
return std::any_cast<T>( &(this->param) );
}
template<typename T>
inline const T *get_param()const noexcept{
tprAssert( this->param.has_value() );
tprAssert( this->param.type().hash_code() == typeid(T).hash_code() );
return std::any_cast<T>( &(this->param) );
}
inline void set_jobType( JobType type_ ){ this->jobType = type_; }
inline JobType get_jobType()const noexcept{ return this->jobType; }
private:
JobType jobType {JobType::Null};
std::any param;
};
#endif
|
turesnake/tprPixelGames | src/Engine/dynamicParam/DyBinary.h | <reponame>turesnake/tprPixelGames
/*
* ======================= DyBinary.h ==========================
* -- tpr --
* CREATE -- 2019.10.18
* MODIFY --
* ----------------------------------------------------------
*/
#ifndef TPR_DY_BINARY_H
#define TPR_DY_BINARY_H
//-------------------- CPP --------------------//
#include <any>
//-------------------- Engine --------------------//
#include "tprAssert.h"
// 通用万能数据包
class DyBinary{
public:
//========== Self ==========//
DyBinary()=default;
template<typename T>
inline T *init()noexcept{
this->data = std::make_any<T>();
return std::any_cast<T>( &(this->data) );
}
template<typename T>
inline T *get()noexcept{
tprAssert( this->data.has_value() );
tprAssert( this->data.type().hash_code() == typeid(T).hash_code() );
return std::any_cast<T>( &(this->data) );
}
template<typename T>
inline const T *get()const noexcept{
tprAssert( this->data.has_value() );
tprAssert( this->data.type().hash_code() == typeid(T).hash_code() );
return std::any_cast<T>( &(this->data) );
}
private:
std::any data;
// 尽管这里的 data 并不会被复制,但 std::any 不支持 move_only type class
// 所以,T 中禁止出现 unique_ptr (嵌套)
// 解法有二:
// -1- 将 unique_ptr 替换为 shadred_ptr
// -2- 自定义 T 的 构造函数 / 移动构造函数 / 移动赋值运算符:
// T(){...}
// T( const T & ){ tprAssert(0); }
// T &operator=( const T & ); // 定义需要在 class 外部
};
#endif
|
turesnake/tprPixelGames | src/Engine/mesh/GameObjMesh.h | <filename>src/Engine/mesh/GameObjMesh.h
/*
* ========================= GameObjMesh.h ==========================
* -- tpr --
* CREATE -- 2018.11.24
* MODIFY --
* ----------------------------------------------------------
* A Mesh class bind to GameObj & AnimAction.
* ----------
* GameObjMesh 和 AnimFrameSet 的区别:
* GameObjMesh 需要 图片资源,
* 而大部分 图片资源,以 gl texName 的形式,存储在 AnimFrameSet 模块中。
* ----------
* 一个 GameObjMesh 实例 拥有:
* 一个 根锚点 / root anchor -- 代表 GameObjMesh 本身
* 数个 子锚点 / child anchor -- 用来绑定其他 GameObjMeshes
* ----------------------------
*/
#ifndef TPR_GAME_OBJ_MESH_H
#define TPR_GAME_OBJ_MESH_H
//=== *** glad FIRST, glfw SECEND *** ===
// Don't include glfw3.h ALONE!!!
#include <glad/glad.h>
#include "pch.h"
//-------------------- Engine --------------------//
#include "ChildMesh.h"
#include "AnimAction.h"
#include "AnimActionEName.h"
#include "RotateScaleData.h"
#include "animSubspeciesId.h"
#include "DyBinary.h"
#include "functorTypes.h"
//--- need ---//
class GameObj;
class GameObjMeshSet;
//-- GameObjMesh 是个 "整合类",不存在进一步的 具象类 --
// GameObjMesh 被轻量化了:
// -- 不再单独管理自己的 VAO,VBO (改为使用全局唯一的 VAO,VBO)
// -- texName 存储在 AnimFrameSet 数据中。GameObjMesh 通过 AnimAction 提供的接口访问它们
// --------
// 当切换 action 时,GameObjMesh实例 并不销毁/新建。而是更新自己的 数据组 (空间最优,时间最劣)
// 这个方法也有其他问题:如果不同类型的 go.GameObjMeshs 数量不同,该怎么办?
class GameObjMesh{
friend class ChildMesh;
friend class GameObjMeshSet;
public:
GameObjMesh( GameObj &goRef_,
const glm::dvec2 &pposOff_,
double zOff_,
bool isVisible_
):
goRef(goRef_),
pposOff( tprRound(pposOff_) ), // Must align to pix
zOff( zOff_),
isVisible(isVisible_)
{
// picMeshUPtr,shadowMeshUPtr 将被延迟到 bind_animAction() 中创建销毁
}
void RenderUpdate_auto();
void RenderUpdate_in_fast_way();
// 新版,相关参数 由其他 set函数 零散地设置
// 最后调用 本函数,完成 正式 重绑定工作
void bind_animAction( int timeStepOff_=0 );
//----- pvtBinary -----//
template< typename T >
inline T *init_pvtBinary()noexcept{
return this->pvtBinary.init<T>();
}
template< typename T >
inline T *get_pvtBinaryPtr()noexcept{
return this->pvtBinary.get<T>();
}
//------------- set -------------//
inline void set_animSubspeciesId( animSubspeciesId_t id_ )noexcept{ this->animSubspeciesId = id_; }
inline void set_animActionEName( AnimActionEName name_ )noexcept{ this->animActionEName = name_; }
inline void set_alti(double alti_)noexcept{ this->alti = alti_; }
inline void set_zOff(double zOff_)noexcept{ this->zOff = zOff_; }
inline void set_uWeight(size_t v_)noexcept{ this->uWeight = v_; }
inline void set_isNeedToBeErase(bool b_)noexcept{ this->isNeedToBeErase = b_; }
inline void set_isVisible(bool b_)noexcept{ this->isVisible = b_; }
inline void accum_alti(double alti_)noexcept{ this->alti += alti_; }
inline void accum_zOff(double zOff_)noexcept{ this->zOff += zOff_; }
inline void accum_pposOff( const glm::dvec2 off_ ){ this->pposOff += off_; }
// speedScale: default=1.0, 值越大,播放速度越缓慢
inline void bind_reset_playSpeedScale( F_R_double functor_ )noexcept{
this->animActionPvtData.reset_playSpeedScale = functor_;
}
//------------- get -------------//
inline size_t get_uWeight()const noexcept{ return this->uWeight; }
inline bool get_isNeedToBeErase()const noexcept{ return this->isNeedToBeErase; }
inline bool get_isVisible()const noexcept{ return this->isVisible; }
inline const AnimAction::PvtData *get_animActionPvtDataPtr()const noexcept{ return &(this->animActionPvtData); }
// 目前仅被 WindAnim 使用
// 也许未来可以被彻底取消 ...
inline std::pair<AnimAction::PlayType, AnimAction::PlayState> get_animAction_state()const noexcept{
return { this->animActionPvtData.playType, this->animActionPvtData.playState };
}
RotateScaleData rotateScaleData {}; // 管理所有 childMesh rotate 操作
private:
//------------- set -------------//
inline void set_pic_renderLayer( RenderLayerType layerType_ )noexcept{
this->picRenderLayerType = layerType_;
if( layerType_ == RenderLayerType::MajorGoes ){
this->isPicFixedZOff = false;
this->picBaseZOff = ViewingBox::boxCenter_2_majorGoes;
}else if( layerType_ == RenderLayerType::BioSoup ){
this->isPicFixedZOff = false;
this->picBaseZOff = ViewingBox::boxCenter_2_bioSoup;
}else{
this->isPicFixedZOff = true;
this->picBaseZOff = ViewingBox::get_renderLayerZOff(layerType_);
}
}
inline void set_pic_shader_program( ShaderProgram *sp_ )noexcept{
tprAssert( this->picMeshUPtr );
this->picMeshUPtr->set_shader_program( sp_ );
}
inline void set_shadow_shader_program( ShaderProgram *sp_ )noexcept{
tprAssert( this->shadowMeshUPtr );
this->shadowMeshUPtr->set_shader_program( sp_ );
}
//------------- get -------------//
inline GLuint get_currentTexName_pic() const noexcept{
return this->animActionPtr->get_currentTexName_pic( this->animActionPvtData );
}
inline GLuint get_currentTexName_shadow() const noexcept{
tprAssert( this->isHaveShadow );
return this->animActionPtr->get_currentTexName_shadow( this->animActionPvtData );
}
//======== vals ========//
GameObj &goRef;
std::unique_ptr<ChildMesh> picMeshUPtr {nullptr};
std::unique_ptr<ChildMesh> shadowMeshUPtr {nullptr}; // 不需要时会被及时释放
// 暂存 gomesh 当前正在播放的 animAction 相关数据
animSubspeciesId_t animSubspeciesId {};
AnimActionEName animActionEName {}; // 使用 string 很不好 ...
glm::dvec2 pposOff {};
//- 以 go.rootAnchor 为 0点的 ppos偏移
// 用来记录,本GameObjMesh 在 go中的 位置(图形)
//-- 大部分情况下(尤其是只有一个 GameObjMesh的 go实例),此值为 0
// 若本 GameObjMesh实例 是 root GameObjMesh。此值必须为0 (不强制...)
// 此值必须 对齐于 像素
double alti {0.0};
// 其实就是 y轴高度值,只影响 pic
// 绝大多数 gomesh,只使用 0.0
// 当要表达 类似 烟雾时,可以用上本值
double zOff {0.0};
//- 一个 go实例 可能拥有数个 GameObjMesh,相互间需要区分 视觉上的前后顺序
//- 此处的 zOff 值只是个 相对偏移值。比如,靠近摄像机的 GameObjMesh zOff +0.1
//- 这个值 多数由 具象go类 填入的。
// *** 只在 goPic 中有意义,在 shadow 中,应该始终为 0;
// 这个值 已经被累加到 z值中.
// ----
// 如果想要一个浮在所有 MajorGo 前方的图像,可以设置 zOff 为 500.0
// 如果想要一个 沉在所有 MajorGo 后方的图像,可设置为 -500.0
double picBaseZOff {};
//- 仅用于 pic-childMesh
// 对于 MajorGo / BioSoup,代表 从 取景盒中点,到 各自深度区间的中点 的偏移值
// 对于 其他 rendertype, 代表 从 camera.zFar, 到 各个 rendertype 对应的 固定值
size_t uWeight {};
// 随机数,方便实现各种功能
// 通常在 job线程中 生成后,传递进来
RenderLayerType picRenderLayerType;
AnimAction *animActionPtr {nullptr};
AnimAction::PvtData animActionPvtData {}; //- 配合 AnimAction 提供的接口 来使用
DyBinary pvtBinary {}; // store dynamic datas
//======== flags ========//
bool isNeedToBeErase {false}; // 请求外部管理者,删除自己
bool isHaveShadow {}; //- 是否拥有 shadow 数据
//- 在 this->init() 之前,此值就被确认了 [被 ChildMesh 使用]
bool isVisible {true}; //- 是否可见 ( go and shadow )
bool isPicFixedZOff {false}; //- 若 renderType 为 MajorGoes / BioSoup, 为 true
// 仅作用于 pic, [被 ChildMesh 使用]
};
#endif
|
turesnake/tprPixelGames | src/Engine/shaderProgram/UniformBlockObj.h | /*
* ========================= UniformBlockObj.h ==========================
* -- tpr --
* CREATE -- 2019.09.22
* MODIFY --
* ----------------------------------------------------------
*/
#ifndef TPR_UNIFORM_BLOCK_OBJ_H
#define TPR_UNIFORM_BLOCK_OBJ_H
//=== *** glad FIRST, glfw SECEND *** ===
// Don't include glfw3.h ALONE!!!
#include<glad/glad.h>
//--- glm - 0.9.9.5 ---
#include "glm_no_warnings.h"
//-------------------- CPP --------------------//
#include <string>
#include <vector>
#include <unordered_map>
//-------------------- Engine --------------------//
#include "tprAssert.h"
namespace ubo{//------------- namespace ubo ----------------
class UniformBlockObj{
public:
UniformBlockObj(GLuint bindPoint_,
GLsizeiptr dataSize_,
const std::string &uboName_ ):
bindPoint(bindPoint_),
dataSize(dataSize_),
uboName(uboName_)
{
glGenBuffers(1, &this->ubo);
glBindBuffer(GL_UNIFORM_BUFFER, this->ubo);
glBufferData(GL_UNIFORM_BUFFER, this->dataSize, nullptr, GL_STATIC_DRAW); // 分配n字节的内存
glBindBuffer(GL_UNIFORM_BUFFER, 0);//- release bind
glBindBufferBase(GL_UNIFORM_BUFFER, this->bindPoint, this->ubo); // set bindPoint
}
// 与本ubo 相关的着色器 执行bind,从而可以访问这个 绑定点idx 的 ubo 数据
inline void bind_2_shaderProgram(GLuint shaderProgram_ )const noexcept{
unsigned int index = glGetUniformBlockIndex( shaderProgram_, this->uboName.c_str() );
glUniformBlockBinding( shaderProgram_, index, this->bindPoint); // set bindPoint
}
inline void write( GLintptr offset_, // 首字节偏移
GLsizeiptr size_, // 写入尺寸
const GLvoid *dataPtr_ )noexcept{
tprAssert( (offset_+size_) <= this->dataSize );
// 现在,所有的东西都配置完毕了,可以开始向 ubo 中添加数据了
glBindBuffer(GL_UNIFORM_BUFFER, this->ubo);
glBufferSubData(GL_UNIFORM_BUFFER, offset_, size_, dataPtr_ );
glBindBuffer(GL_UNIFORM_BUFFER, 0);//- release bind
}
private:
GLuint ubo {};
GLuint bindPoint {};
GLsizeiptr dataSize {}; //- 也许会被拆分为 n * ent, 但 本class 并不关心
std::string uboName {};
};
}//------------- namespace ubo: end ----------------
#endif
|
turesnake/tprPixelGames | src/Engine/dynamicParam/DyFunctor.h | /*
* ======================= DyFunctor.h ==========================
* -- tpr --
* CREATE -- 2020.02.12
* MODIFY --
* ----------------------------------------------------------
*/
#ifndef TPR_DY_FUNCTOR_H
#define TPR_DY_FUNCTOR_H
//-------------------- CPP --------------------//
#include <any>
//-------------------- Engine --------------------//
#include "tprAssert.h"
// 通用万能 函数对象
class DyFunctor{
public:
DyFunctor()=default;
template<typename T>
inline T *init( T functor_ )noexcept{
this->data = std::make_any<T>( functor_ );
return std::any_cast<T>( &(this->data) );
}
template<typename T>
inline T *get()noexcept{
tprAssert( this->data.has_value() );
tprAssert( this->data.type().hash_code() == typeid(T).hash_code() );
return std::any_cast<T>( &(this->data) );
}
private:
std::any data; // 存储一枚 functor,允许复制
};
#endif
|
turesnake/tprPixelGames | src/Engine/blueprint/blueprint_inn.h | <reponame>turesnake/tprPixelGames<gh_stars>100-1000
/*
* ======================= blueprint_inn.h =======================
* -- tpr --
* CREATE -- 2019.12.07
* MODIFY --
* ----------------------------------------------------------
* only included by blueprint.cpp
*/
#ifndef TPR_BLUE_PRINT_INN_H
#define TPR_BLUE_PRINT_INN_H
//-------------------- Engine --------------------//
#include "PlotBlueprint.h"
#include "YardBlueprint.h"
#include "VillageBlueprint.h"
namespace blueprint {//------------------ namespace: blueprint start ---------------------//
namespace blueP_inn {//----------- namespace: blueP_inn ----------------//
// blueprint 中的数据 全部是只读的 (为了支持多线程访问)
// 为了存储额外的 变量,使用以下 class 来实现
//-----------------//
// Plot
//-----------------//
class VarType_Plot_Manager{
class VarType{
friend class VarType_Plot_Manager;
public:
VarType( bool isAllInstanceUseSamePlan_,
const VarTypeDatas_Plot *vtPtr_ ):
isAllInstanceUseSamePlan(isAllInstanceUseSamePlan_),
vtPtr(vtPtr_)
{}
private:
inline const GoSpec &apply_a_goSpec( size_t uWeight_ )noexcept{
const GoSpec &goSpecRef = this->vtPtr->apply_rand_goSpec( uWeight_ );
if( this->isAllInstanceUseSamePlan ){
//-- 统一值 只生成一次,并永久保留
if( !this->isUnifiedValsset ){
this->isUnifiedValsset = true;
this->unifiedGoSpecPtr = &goSpecRef;
}
//-- 直接获得 统一值
return *(this->unifiedGoSpecPtr);
}else{
//-- 每次都独立分配 yardId --
return goSpecRef;
}
}
//===== vals =====//
bool isAllInstanceUseSamePlan {}; // 是否 本类型的所有个体,共用一个 实例化对象
const VarTypeDatas_Plot *vtPtr {};
//---
const GoSpec *unifiedGoSpecPtr {nullptr};
bool isUnifiedValsset {false};
};
public:
explicit VarType_Plot_Manager( PlotBlueprint &plot_ ){
for( const auto &type : plot_.get_varTypes() ){
const auto *vtPtr = plot_.get_varTypeDataPtr_Plot( type );
this->varTypes_P.insert({ type, VarType{ vtPtr->get_isAllInstanceUseSamePlan(), vtPtr } });
}
}
inline const GoSpec &apply_a_goSpec( VariableTypeIdx type_, size_t uWeight_ )noexcept{
tprAssert( this->varTypes_P.find(type_) != this->varTypes_P.end() );
return this->varTypes_P.at(type_).apply_a_goSpec( uWeight_ );
}
private:
std::unordered_map<VariableTypeIdx, VarType> varTypes_P {};
};
//-----------------//
// Yard
//-----------------//
class VarType_Yard_Manager{
class VarType_Y_MajorGo{
friend class VarType_Yard_Manager;
public:
VarType_Y_MajorGo( bool isAllInstanceUseSamePlan_,
bool isPlotBlueprint_,
const VarTypeDatas_Yard_MajorGo *vtPtr_ ):
isAllInstanceUseSamePlan(isAllInstanceUseSamePlan_),
isPlotBlueprint(isPlotBlueprint_),
vtPtr(vtPtr_)
{}
private:
//-- 以下 2 函数,只有一个被使用
inline const GoSpec &apply_a_goSpec( size_t uWeight_ )noexcept{
tprAssert( !this->isPlotBlueprint );
const GoSpec &goSpecRef = this->vtPtr->apply_rand_goSpec( uWeight_ );
if( this->isAllInstanceUseSamePlan ){
//-- 统一值 只生成一次,并永久保留
if( !this->isUnifiedValsset ){
this->isUnifiedValsset = true;
this->unifiedGoSpecPtr = &goSpecRef;
}
//-- 直接获得 统一值
return *(this->unifiedGoSpecPtr);
}else{
//-- 每次都独立分配 yardId --
return goSpecRef;
}
}
inline plotBlueprintId_t apply_a_plotBlueprintId( size_t uWeight_ )noexcept{
tprAssert( this->isPlotBlueprint );
const auto &plotIdsRef = this->vtPtr->get_plotIds();
tprAssert( !plotIdsRef.empty() );
if( this->isAllInstanceUseSamePlan ){
//-- 统一值 只生成一次,并永久保留
if( !this->isUnifiedValsset ){
this->isUnifiedValsset = true;
this->unifiedPlotId = plotIdsRef.at( (uWeight_ + 751446131) % plotIdsRef.size() );
}
//-- 直接获得 统一值
return this->unifiedPlotId;
}else{
//-- 每次都独立分配 yardId --
return plotIdsRef.at( (uWeight_ + 751446131) % plotIdsRef.size() );
}
}
//===== vals =====//
bool isAllInstanceUseSamePlan {}; // 是否 本类型的所有个体,共用一个 实例化对象
bool isPlotBlueprint {}; // 本变量是否为一个 plot
const VarTypeDatas_Yard_MajorGo *vtPtr {};
//-- 以下 2 数据,只有一个被使用
const GoSpec *unifiedGoSpecPtr {nullptr};
plotBlueprintId_t unifiedPlotId {};
bool isUnifiedValsset {false};
};
class VarType_Y_FloorGo{
friend class VarType_Yard_Manager;
public:
VarType_Y_FloorGo( bool isAllInstanceUseSamePlan_,
const VarTypeDatas_Yard_FloorGo *vtPtr_ ):
isAllInstanceUseSamePlan(isAllInstanceUseSamePlan_),
vtPtr(vtPtr_)
{}
private:
inline const GoSpec &apply_a_goSpec( size_t uWeight_ )noexcept{
const GoSpec &goSpecRef = this->vtPtr->apply_rand_goSpec( uWeight_ );
if( this->isAllInstanceUseSamePlan ){
//-- 统一值 只生成一次,并永久保留
if( !this->isUnifiedValsset ){
this->isUnifiedValsset = true;
this->unifiedGoSpecPtr = &goSpecRef;
}
//-- 直接获得 统一值
return *(this->unifiedGoSpecPtr);
}else{
//-- 每次都独立分配 yardId --
return goSpecRef;
}
}
//===== vals =====//
bool isAllInstanceUseSamePlan {}; // 是否 本类型的所有个体,共用一个 实例化对象
const VarTypeDatas_Yard_FloorGo *vtPtr {};
//---
const GoSpec *unifiedGoSpecPtr {nullptr};
bool isUnifiedValsset {false};
};
public:
explicit VarType_Yard_Manager( YardBlueprint &yard_ ){
for( const auto &type : yard_.get_majorGo_varTypes() ){
const auto *vtPtr = yard_.get_majorGo_varTypeDataPtr_Yard( type );
this->varTypes_Y_majorGo.insert({ type, VarType_Y_MajorGo{vtPtr->get_isAllInstanceUseSamePlan(),
vtPtr->get_isPlotBlueprint(),
vtPtr } });
}
for( const auto &type : yard_.get_floorGo_varTypes() ){
const auto *vtPtr = yard_.get_floorGo_varTypeDataPtr_Yard( type );
this->varTypes_Y_floorGo.insert({ type, VarType_Y_FloorGo{vtPtr->get_isAllInstanceUseSamePlan(),
vtPtr } });
}
}
inline const GoSpec &apply_a_majorGoSpec( VariableTypeIdx type_, size_t uWeight_ )noexcept{
tprAssert( this->varTypes_Y_majorGo.find(type_) != this->varTypes_Y_majorGo.end() );
return this->varTypes_Y_majorGo.at(type_).apply_a_goSpec( uWeight_ );
}
inline const GoSpec &apply_a_floorGoSpec( VariableTypeIdx type_, size_t uWeight_ )noexcept{
tprAssert( this->varTypes_Y_floorGo.find(type_) != this->varTypes_Y_floorGo.end() );
return this->varTypes_Y_floorGo.at(type_).apply_a_goSpec( uWeight_ );
}
inline plotBlueprintId_t apply_a_plotBlueprintId( VariableTypeIdx type_, size_t uWeight_ )noexcept{
tprAssert( this->varTypes_Y_majorGo.find(type_) != this->varTypes_Y_majorGo.end() );
return this->varTypes_Y_majorGo.at(type_).apply_a_plotBlueprintId( uWeight_ );
}
private:
std::unordered_map<VariableTypeIdx, VarType_Y_MajorGo> varTypes_Y_majorGo {};
std::unordered_map<VariableTypeIdx, VarType_Y_FloorGo> varTypes_Y_floorGo {};
};
//-----------------//
// Village
//-----------------//
class VarType_Village_Manager{
class VarType{
friend class VarType_Village_Manager;
public:
VarType( bool isAllInstanceUseSamePlan_,
const VarTypeDatas_Village *vtPtr_ ):
isAllInstanceUseSamePlan(isAllInstanceUseSamePlan_),
vtPtr(vtPtr_)
{}
private:
yardBlueprintId_t apply_a_yardBlueprintId( size_t uWeight_, NineDirection yardDir_ )noexcept;
//----- vals -----//
bool isAllInstanceUseSamePlan {}; // 是否 本类型的所有个体,共用一个 实例化对象
const VarTypeDatas_Village *vtPtr {};
yardBlueprintId_t unifiedYardId {};
bool isUnifiedValsset {false};
};
public:
explicit VarType_Village_Manager( VillageBlueprint &village_ ){
for( const auto &type : village_.get_varTypes() ){
const auto *vtPtr = village_.get_varTypeDataPtr_Village( type );
this->varTypes.insert({ type, VarType{ vtPtr->get_isAllInstanceUseSamePlan(), vtPtr } });
}
}
inline yardBlueprintId_t apply_a_yardBlueprintId( VariableTypeIdx type_, size_t uWeight_, NineDirection yardDir_ )noexcept{
tprAssert( this->varTypes.find(type_) != this->varTypes.end() );
return this->varTypes.at(type_).apply_a_yardBlueprintId( uWeight_, yardDir_ );
}
private:
std::unordered_map<VariableTypeIdx, VarType> varTypes {};
};
}//-------------- namespace: blueP_inn end ----------------//
}//--------------------- namespace: blueprint end ------------------------//
#endif
|
turesnake/tprPixelGames | src/Engine/gl/gl_funcs.h | <filename>src/Engine/gl/gl_funcs.h
/*
* ========================= gl_funcs.h ===================
* -- tpr --
* CREATE -- 2018.11.21
* MODIFY --
* ----------------------------------------------------------
* gl 模块中的 公共函数
* ----------------------------
*/
#ifndef TPR_GL_FUNC_H
#define TPR_GL_FUNC_H
//=== *** glad FIRST, glfw SECEND *** ===
// Don't include glfw3.h ALONE!!!
#include<glad/glad.h>
#include<GLFW/glfw3.h>
//------------------- Engine --------------------//
#include "IntVec.h"
//------ gl_support.cpp -----//
void glfw_init();
void glfw_hints_set();
void glfw_window_creat();
void glfw_oth_set();
void glfw_callback_set();
void glad_init();
void glad_set();
#endif
|
turesnake/tprPixelGames | src/Engine/input/Mouse.h | /*
* ========================= Mouse.h ==========================
* -- tpr --
* CREATE -- 2020.01.27
* MODIFY --
* ----------------------------------------------------------
*/
#ifndef TPR_Mouse_H
#define TPR_Mouse_H
//--- glm - 0.9.9.5 ---
#include "glm_no_warnings.h"
class Mouse{
public:
Mouse()=default;
glm::dvec2 cursorDPos {};
bool leftButton {}; // true: press
bool rightButton {}; // true: press
bool midButton {}; // true: press
// 屏蔽鼠标滚轮 功能 ...
};
#endif
|
turesnake/tprPixelGames | src/Engine/UI/UIGoSpecFromJson.h | /*
* =================== UIGoSpecFromJson.h ==========================
* -- tpr --
* CREATE -- 2019.12.12
* MODIFY --
* ----------------------------------------------------------
*/
#ifndef TPR_UI_GO_SPEC_FROM_JSON_H
#define TPR_UI_GO_SPEC_FROM_JSON_H
//--- glm - 0.9.9.5 ---
#include "glm_no_warnings.h"
//-------------------- CPP --------------------//
#include <string>
#include <unordered_set>
#include <unordered_map>
#include <memory>
#include <functional> // hash
//-------------------- Engine --------------------//
#include "tprAssert.h"
#include "GameObjType.h"
#include "Move.h"
#include "PubBinary2.h"
class GameObj;
class UIGoSpecFromJson{
public:
std::string goSpeciesName {};
goSpeciesId_t speciesId {};
//----- enum -----//
GameObjFamily family {};
//----- bool -----//
//----- numbers -----//
MoveType moveType {};
SpeedLevel moveSpeedLvl {};
//...
//======== static ========//
static void assemble_2_newUIGo( goSpeciesId_t specID_, GameObj &goRef_ );
inline static UIGoSpecFromJson &create_new_UIGoSpecFromJson( const std::string &name_ ){
std::hash<std::string> hasher;
goSpeciesId_t id = static_cast<goSpeciesId_t>( hasher(name_) ); // size_t -> uint64_t
std::unique_ptr<UIGoSpecFromJson> uptr ( new UIGoSpecFromJson() ); // can't use std::make_unique
auto [insertIt, insertBool] = UIGoSpecFromJson::dataUPtrs.emplace( id, std::move(uptr) );
tprAssert( insertBool );
UIGoSpecFromJson &ref = *(insertIt->second);
//---
ref.goSpeciesName = name_;
ref.speciesId = id;
UIGoSpecFromJson::insert_2_uiGoSpeciesIds_names_containers( id, name_ );
//---
return ref;
}
inline static goSpeciesId_t str_2_uiGoSpeciesId( const std::string &name_ ){
tprAssert( UIGoSpecFromJson::names_2_ids.find(name_) != UIGoSpecFromJson::names_2_ids.end() );
return UIGoSpecFromJson::names_2_ids.at(name_);
}
inline static const UIGoSpecFromJson &get_uiGoSpecFromJsonRef( goSpeciesId_t id_ ){
tprAssert( UIGoSpecFromJson::dataUPtrs.find(id_) != UIGoSpecFromJson::dataUPtrs.end() );
return *(UIGoSpecFromJson::dataUPtrs.at(id_));
}
inline static bool find_from_initFuncs( goSpeciesId_t goSpeciesId_ ){
return (UIGoSpecFromJson::initFuncs.find(goSpeciesId_) != UIGoSpecFromJson::initFuncs.end());
}
inline static void call_initFunc( goSpeciesId_t id_, GameObj &goRef_, const DyParam &dyParams_ ){
tprAssert( UIGoSpecFromJson::find_from_initFuncs(id_) );
UIGoSpecFromJson::initFuncs.at(id_)( goRef_, dyParams_ );
}
inline static void insert_2_initFuncs( const std::string &goTypeName_, const F_GO_INIT &functor_ ){
goSpeciesId_t id = UIGoSpecFromJson::str_2_uiGoSpeciesId( goTypeName_ );
auto [insertIt, insertBool] = UIGoSpecFromJson::initFuncs.emplace( id, functor_ );
tprAssert( insertBool );
}
private:
UIGoSpecFromJson()=default;
inline static void insert_2_uiGoSpeciesIds_names_containers( goSpeciesId_t id_, const std::string &name_ ){
auto out1 = UIGoSpecFromJson::ids_2_names.emplace( id_, name_ );
auto out2 = UIGoSpecFromJson::names_2_ids.emplace( name_, id_ );
tprAssert( out1.second );
tprAssert( out2.second );
}
//======== static ========//
// 资源持续整个游戏生命期,不用释放
static std::unordered_map<goSpeciesId_t, std::unique_ptr<UIGoSpecFromJson>> dataUPtrs;
static std::unordered_map<goSpeciesId_t, std::string> ids_2_names;
static std::unordered_map<std::string, goSpeciesId_t> names_2_ids;
static std::unordered_map<goSpeciesId_t, F_GO_INIT> initFuncs;
};
namespace json{//------------- namespace json ----------------
void parse_uiGoJsonFile();
}//------------- namespace json: end ----------------
#endif
|
turesnake/tprPixelGames | src/Engine/ecoSys/ecoObjBorder/EcoObjBorder.h | /*
* ====================== EcoObjBorder.h =======================
* -- tpr --
* CREATE -- 2020.02.14
* MODIFY --
* ----------------------------------------------------------
*/
#ifndef TPR_ECO_OBJ_BORDER_H
#define TPR_ECO_OBJ_BORDER_H
#include "pch.h"
//-------------------- CPP --------------------//
#include <tuple>
//-------------------- Engine --------------------//
#include "NineDirection.h"
// 单帧 位图数据,可以分配 ecoObj-边界(mapent为单位)
//
class EcoObjBorder{
public:
EcoObjBorder()
{
this->frame.resize( ENTS_PER_SECTION<size_t> * ENTS_PER_SECTION<size_t>, NineDirection::Center );
}
// param: mapent 相对与 ecoobj 左下角的 mposOff
inline NineDirection assign_mapent_to_nearFour_ecoObjs_dir( IntVec2 mposOff_ )const noexcept{
tprAssert( (mposOff_.x>=0) && (mposOff_.x<ENTS_PER_SECTION<>) &&
(mposOff_.y>=0) && (mposOff_.y<ENTS_PER_SECTION<>) );
size_t idx = cast_2_size_t(mposOff_.y * ENTS_PER_SECTION<> + mposOff_.x);
return this->frame.at( idx );
}
//======= static =======//
// 从 ecoObjBorder.png 读取数据
static void init();
inline static const EcoObjBorder *apply_rand_ecoObjBorderPtr( size_t uWeight_ )noexcept{
size_t idx = ( uWeight_ + 1504471 ) % EcoObjBorder::frames.size();
return EcoObjBorder::frames.at(idx).get();
}
private:
static std::tuple<IntVec2, size_t, std::string> parse_plotJsonFile();
inline static EcoObjBorder &create_new_ecoObjBorder(){
EcoObjBorder::frames.push_back( std::make_unique<EcoObjBorder>() );
return *(EcoObjBorder::frames.back());
}
//----- vals -----//
std::vector<NineDirection> frame {}; // 单帧数据
//======= static =======//
static std::vector<std::unique_ptr<EcoObjBorder>> frames; // 存储 若干帧
};
#endif
|
turesnake/tprPixelGames | src/Script/gameObjs/majorGos/bushs/Bush.h | /*
* ========================= Bush.h ==========================
* -- tpr --
* CREATE -- 2019.10.09
* MODIFY --
* ----------------------------------------------------------
*/
#ifndef TPR_GO_BUSH_C_H
#define TPR_GO_BUSH_C_H
//-------------------- Engine --------------------//
#include "GameObj.h"
#include "DyParam.h"
namespace gameObjs{//------------- namespace gameObjs ----------------
// 类似 Grass,Bush 也是数种 bush亚种 的合并类。
// 它们拥有相同的 动画习性(风吹)但在被具体破坏后,会调用不同的 技能函数(未实现)
// 如果某种 bush 比较特殊,未来就要为它制作专门的 具象go类
class Bush{
public:
static void init(GameObj &goRef_,const DyParam &dyParams_ );
private:
static void bind( GameObj &goRef_ );
static void rebind( GameObj &goRef_ );
//--- callback ---//
static void OnRenderUpdate( GameObj &goRef_ );
static void OnLogicUpdate( GameObj &goRef_ );
static void OnActionSwitch( GameObj &goRef_, ActionSwitchType type_ );
};
}//------------- namespace gameObjs: end ----------------
#endif
|
turesnake/tprPixelGames | src/Engine/dynamicParam/DyParam.h | /*
* ========================= DyParam.h ==========================
* -- tpr --
* CREATE -- 2019.08.25
* MODIFY --
* ----------------------------------------------------------
* fast dynamic param
*/
#ifndef TPR_DY_PARAM_H
#define TPR_DY_PARAM_H
//-------------------- CPP --------------------//
#include <vector>
//-------------------- Engine --------------------//
#include "tprAssert.h"
//-- only used by create_gos_in_field()
// the paramData's lifetime is managed by caller
// DyParam instance only transfer the data-ptr
class DyParam{
public:
DyParam() = default;
template< typename T >
inline void insert_ptr( T *ptr_ )noexcept{
this->typeHash = typeid(T).hash_code();
this->ptr = static_cast<void*>(ptr_);
}
template< typename T >
inline const T*get_binaryPtr()const noexcept{
tprAssert( this->ptr != nullptr );
tprAssert( typeid(T).hash_code() == this->typeHash );
return static_cast<T*>( this->ptr );
}
inline size_t get_typeHash()const noexcept{ return this->typeHash; }
inline bool is_Nil()const noexcept{ return (this->ptr == nullptr); }
private:
void *ptr {nullptr};
size_t typeHash {0};
};
extern DyParam emptyDyParam;
#endif
|
turesnake/tprPixelGames | src/Engine/resource/esrc_animFrameSet.h | /*
* ========================= esrc_animFrameSet.h ==========================
* -- tpr --
* CREATE -- 2019.04.19
* MODIFY --
* ----------------------------------------------------------
*/
#ifndef TPR_ESRC_ANIM_FRAME_SET_H
#define TPR_ESRC_ANIM_FRAME_SET_H
//-------------------- CPP --------------------//
#include <unordered_map>
#include <string>
//-------------------- Engine --------------------//
#include "AnimFrameSet.h"
namespace esrc {//------------------ namespace: esrc -------------------------//
AnimSubspecies &find_or_insert_new_animSubspecies( animSubspeciesId_t id_ );
//AnimSubspecies &get_animSubspeciesRef( animSubspeciesId_t id_ ); // not used
AnimFrameSet &insert_new_animFrameSet( const std::string &name_ );
animSubspeciesId_t apply_a_random_animSubspeciesId( const std::string &animFrameSetName_,
const std::string &label_,
size_t uWeight_ );
AnimAction *get_animActionPtr( animSubspeciesId_t subId_,
NineDirection dir_,
BrokenLvl brokenLvl_,
AnimActionEName actionEName_ );
//-- special SubspeciesId --
void set_nilCollide_emptyPixId( animSubspeciesId_t id_ )noexcept;
void set_squareCollide_emptyPixId( animSubspeciesId_t id_ )noexcept;
animSubspeciesId_t get_nilCollide_emptyPixId()noexcept;
animSubspeciesId_t get_squareCollide_emptyPixId()noexcept;
void set_fieldRimId( animSubspeciesId_t id_ )noexcept;
animSubspeciesId_t get_fieldRimId()noexcept;
}//---------------------- namespace: esrc -------------------------//
#endif
|
turesnake/tprPixelGames | src/Script/gameObjs/bioSoup/BioSoupState.h | <filename>src/Script/gameObjs/bioSoup/BioSoupState.h
/*
* ====================== BioSoupState.h =======================
* -- tpr --
* CREATE -- 2020.02.29
* MODIFY --
* ----------------------------------------------------------
*/
#ifndef TPR_BIO_SOUP_STATE_H
#define TPR_BIO_SOUP_STATE_H
//-------------------- Engine --------------------//
#include "MapAltitude.h"
namespace gameObjs::bioSoup {//------------- namespace gameObjs::bioSoup ----------------
enum class State{
NotExist, // 不存在
Active, // 激活
Inertia, // 惰性
};
inline State calc_bioSoupState_by_mapAlti( MapAltitude mapAlti_ ){
if( mapAlti_.get_val() < -23.0 ){ return State::Inertia;
}else if( mapAlti_.get_val() < 0.0 ){ return State::Active;
}else{ return State::NotExist;
}
}
}//------------- namespace gameObjs::bioSoup: end ----------------
#endif
|
turesnake/tprPixelGames | src/Script/components/windAnim/WindAnim.h | /*
* ======================== WindAnim.h ==========================
* -- tpr --
* CREATE -- 2020.01.16
* MODIFY --
* ----------------------------------------------------------
*/
#ifndef TPR_COMONENT_WIND_ANIM_H
#define TPR_COMONENT_WIND_ANIM_H
//-------------------- CPP --------------------//
#include <vector>
#include <string>
#include <memory>
//-------------------- Engine --------------------//
#include "AnimActionEName.h"
#include "GameObjMesh.h"
namespace component{//------------- namespace component ----------------
// 辅助 go 实现 风吹动画
// manual:
// -1- 在 具象go类 pvt class 中,包含本实例
// -2- 先调用 insert_goMesh(), 收集所有 参与风吹动画的 gomesh
// -3- 最后调用 init(); 彻底完成 初始化
// -4- each render frame, call updat()
//
class WindAnim{
public:
class GoMeshData{
public:
GoMeshData( GameObjMesh* goMeshPtr_,
size_t windDelayStepCount_,
size_t windDelayIdx_,
bool isWindClockWorking_):
goMeshPtr(goMeshPtr_),
windDelayStepCount(windDelayStepCount_),
windDelayIdx(windDelayIdx_),
isWindClockWorking(isWindClockWorking_)
{}
//----- vals -----//
GameObjMesh* goMeshPtr;
size_t windDelayStepCount; // dynamicVal, count down
size_t windDelayIdx; // for WindClock::get_playSpeedScale()
bool isWindClockWorking;
};
//======= Self =======//
WindAnim()=default;
// first call
inline void insert_goMesh( GameObjMesh* goMeshPtr_, size_t windDelayIdx_ )noexcept{
std::unique_ptr<GoMeshData> uptr = std::make_unique<GoMeshData>( goMeshPtr_, 5, windDelayIdx_, false ); // 初始值 5,最简便的实现
this->goMeshs.push_back( std::move(uptr));
}
// final call
void init( const std::vector<AnimActionEName> *ActionEName_poolPtr_ )noexcept;
void update()noexcept;
// 可能要被改为 private ...
inline AnimActionEName apply_a_windAnimActionEName()noexcept{
this->windAnimActionEName_poolIdx++;
if( this->windAnimActionEName_poolIdx >= this->ActionEName_poolPtr->size() ){
this->windAnimActionEName_poolIdx = 0;
}
return this->ActionEName_poolPtr->at( this->windAnimActionEName_poolIdx );
}
//======= static =======//
static inline size_t apply_a_goMesh_windDelayStep()noexcept{
WindAnim::goMesh_windDelaySteps_poolIdx++;
if( WindAnim::goMesh_windDelaySteps_poolIdx >= WindAnim::goMesh_windDelaySteps_pool.size() ){
WindAnim::goMesh_windDelaySteps_poolIdx = 0;
}
return WindAnim::goMesh_windDelaySteps_pool.at(WindAnim::goMesh_windDelaySteps_poolIdx);
}
static inline size_t apply_a_go_windDelayStep()noexcept{
WindAnim::go_windDelaySteps_poolIdx++;
if( WindAnim::go_windDelaySteps_poolIdx >= WindAnim::go_windDelaySteps_pool.size() ){
WindAnim::go_windDelaySteps_poolIdx = 0;
}
return WindAnim::go_windDelaySteps_pool.at(WindAnim::go_windDelaySteps_poolIdx);
}
static void init_for_static()noexcept; // MUST CALL IN MAIN !!!
private:
std::unique_ptr<double> testUPtr {nullptr};
size_t windClockCheckStepCount {}; // count down
size_t oldWindClockCount {0};
size_t windAnimActionEName_poolIdx {0};
const std::vector<AnimActionEName> *ActionEName_poolPtr;
// 实际容器,由各 具象go类 实现
// 仅提供 只读指针 到此
std::vector<std::unique_ptr<GoMeshData>> goMeshs {}; // 参与 风吹动画的 gomeshPtr 集
//======= static =======//
static size_t goMesh_windDelaySteps_poolIdx;
static size_t go_windDelaySteps_poolIdx;
static std::vector<size_t> goMesh_windDelaySteps_pool; // 1000 ents
static std::vector<size_t> go_windDelaySteps_pool; // 100 ents
};
}//------------- namespace component: end ----------------
#endif
|
turesnake/tprPixelGames | src/Engine/multiThread/jobs_all.h | <reponame>turesnake/tprPixelGames
/*
* ========================== jobs_all.h =======================
* -- tpr --
* CREATE -- 2019.04.25
* MODIFY --
* ----------------------------------------------------------
*/
#ifndef TPR_JOBS_ALL_H
#define TPR_JOBS_ALL_H
//-------------------- Engine --------------------//
#include "Job.h"
#include "chunkKey.h"
#include "sectionKey.h"
// POD
// job.argBinary
// use std::any to pass
struct ArgBinary_Create_Job_Chunk{
chunkKey_t chunkKey;
};
void create_job_chunk_main( const Job &job_ );
// POD
// job.argBinary
// use std::any to pass
struct ArgBinary_Create_Job_EcoObj{
sectionKey_t ecoObjKey;
};
void create_job_ecoObj_main( const Job &job_ );
#endif
|
turesnake/tprPixelGames | src/Engine/tools/functorTypes.h | /*
* ========================= functorTypes.h ==========================
* -- tpr --
* CREATE -- 2019.10.20
* MODIFY --
* ----------------------------------------------------------
*/
#ifndef TPR_FUNCTOR_TYPES_H
#define TPR_FUNCTOR_TYPES_H
//--- glm - 0.9.9.5 ---
#include "glm_no_warnings.h"
//-------------------- CPP --------------------//
#include <functional>
using F_void = std::function<void()>;
using F_bool = std::function<bool()>;
using F_R_int = std::function<int()>;
using F_R_double = std::function<double()>;
#endif
|
turesnake/tprPixelGames | src/Engine/ecoSys/EcoObj.h | /*
* ========================== EcoObj.h =======================
* -- tpr --
* CREATE -- 2019.03.02
* MODIFY --
* ----------------------------------------------------------
*/
#ifndef TPR_ECO_OBJ_H
#define TPR_ECO_OBJ_H
#include "pch.h"
//-------------------- Engine --------------------//
#include "sectionKey.h"
#include "EcoSysPlanType.h"
#include "Quad.h"
#include "occupyWeight.h"
#include "RGBA.h"
#include "GameObjType.h"
#include "Density.h"
#include "GoSpecData.h"
#include "colorTableId.h"
#include "GoDataForCreate.h"
#include "mapEntKey.h"
#include "blueprint.h"
#include "fieldKey.h"
#include "EcoObjBorder.h"
#include "DensityPool.h"
class EcoSysPlan;
//- 一个在游戏地图上存在的 实实在在的区域。
//- 在游戏世界中,每个 section左下角,都放置一个 EcoSysPlan 数据集
// 存储了这个 EcoSysPlan 实例 的各种数据 (用来生成地图)
// ----
// 这组数据会暂时 长期存储在 mem/disk
class EcoObj{
public:
EcoObj() = default;
void init( sectionKey_t sectionKey_ );
void init_fstOrder( sectionKey_t sectionKey_ );
const DensityPool &get_densityPool( Density density_ )const noexcept{
tprAssert( this->densityPoolsPtr->find(density_) != this->densityPoolsPtr->end() );
return *(this->densityPoolsPtr->at(density_));
}
inline IntVec2 get_mpos() const noexcept{ return this->mpos; }
inline ecoSysPlanId_t get_ecoSysPlanId() const noexcept{ return this->ecoSysPlanId; }
inline EcoSysPlanType get_ecoSysPlanType() const noexcept{ return this->ecoSysPlanType; }
inline double get_densitySeaLvlOff() const noexcept{ return this->densitySeaLvlOff; }
inline sectionKey_t get_sectionKey() const noexcept{ return this->sectionKey; }
inline size_t get_uWeight() const noexcept{ return this->uWeight; }
inline occupyWeight_t get_occupyWeight() const noexcept{ return this->occupyWeight; }
inline colorTableId_t get_colorTableId()const noexcept{ return this->colorTableId; }
inline const std::vector<double> *get_densityDivideValsPtr() const noexcept{ return this->densityDivideValsPtr; }
inline const EcoObjBorder *get_ecoObjBorderPtr()const noexcept{ return this->ecoObjBorderPtr; }
inline blueprint::yardBlueprintId_t get_natureFloorYardId()const noexcept{ return this->natureFloorYardId; }
inline bool is_find_in_natureFloorDensitys( Density density_ )const noexcept{
return (this->natureFloorDensitysPtr->find(density_) != this->natureFloorDensitysPtr->end());
}
inline std::optional<const GoDataForCreate*> find_majorGoDataForCreatePtr( mapEntKey_t key_ )const noexcept{
if( this->majorGoDatasForCreate.find(key_) == this->majorGoDatasForCreate.end() ){
return std::nullopt;
}else{
return { this->majorGoDatasForCreate.at(key_).get() };
}
}
inline std::optional<const GoDataForCreate*> find_floorGoDataForCreatePtr( mapEntKey_t key_ )const noexcept{
if( this->floorGoDatasForCreate.find(key_) == this->floorGoDatasForCreate.end() ){
return std::nullopt;
}else{
return { this->floorGoDatasForCreate.at(key_).get() };
}
}
inline bool is_find_in_artifactFieldKeys( fieldKey_t key_ )const noexcept{
return (artifactFieldKeys.find(key_) != this->artifactFieldKeys.end() );
}
//======== static funcs ========//
static void calc_nearFour_node_ecoObjKey( sectionKey_t targetKey_,
std::vector<sectionKey_t> &container_ );
private:
void copy_datas_from_ecoSysPlan( EcoSysPlan *targetEcoPtr_ );
//======== vals ========//
sectionKey_t sectionKey {};
//MapCoord mcpos {}; //- [left-bottom]
IntVec2 mpos {}; // [left-bottom]
size_t uWeight {}; // [0, 9999]
occupyWeight_t occupyWeight {0}; //- 抢占权重。 [0,15]
//- 数值越高,此 ecosys 越强势,能占据更多fields
//- [just mem]
ecoSysPlanId_t ecoSysPlanId {};
EcoSysPlanType ecoSysPlanType {EcoSysPlanType::Forest};
colorTableId_t colorTableId {}; // same with ecoPlan.colorTableId
//-- 本 ecoObj mpos 在 世界坐标中的 奇偶性 --
// 得到的值将会是 {0,0}; {1,0}; {0,1}; {1,1} 中的一种
IntVec2 oddEven {};
const std::vector<double> *densityDivideValsPtr {}; //- 6 ents, each_ent: [-100.0, 100.0]
//-- 独立数据 --
const std::map<Density, std::unique_ptr<DensityPool>> *densityPoolsPtr {nullptr};
// 暂时没有确定,是否重分配 densitypools 数据
// ...
// 目前就是直接借用 ecoplan 里的原版数据
double densitySeaLvlOff {0.0};
//----- blueprint datas -----//
std::unordered_map<mapEntKey_t, std::unique_ptr<GoDataForCreate>> majorGoDatasForCreate {};// key 绝对值
std::unordered_map<mapEntKey_t, std::unique_ptr<GoDataForCreate>> floorGoDatasForCreate {};// key 绝对值
// 表示 哪些 field 已经存在蓝图数据了(不用生成 nature go 了)
std::unordered_set<fieldKey_t> artifactFieldKeys {}; // key 绝对值
blueprint::villageBlueprintId_t villageBlueprintId {};
//-- nature_floorYard --//
blueprint::yardBlueprintId_t natureFloorYardId {};
const std::set<Density> *natureFloorDensitysPtr {nullptr};
const EcoObjBorder *ecoObjBorderPtr {nullptr};
};
#endif
|
turesnake/tprPixelGames | src/Engine/resource/esrc_jobQue.h | /*
* ========================= esrc_jobQue.h ==========================
* -- tpr --
* CREATE -- 2019.04.24
* MODIFY --
* ----------------------------------------------------------
*/
#ifndef TPR_ESRC_JOB_QUE_H
#define TPR_ESRC_JOB_QUE_H
//-------------------- CPP --------------------//
#include <memory>
//-------------------- Engine --------------------//
#include "Job.h"
namespace esrc {//------------------ namespace: esrc -------------------------//
void atom_exitJobThreadsFlag_store( bool _val );
bool atom_exitJobThreadsFlag_load();
void atom_push_back_2_jobQue( std::shared_ptr<Job> jobSPtr_ );
bool atom_is_jobQue_empty();
std::shared_ptr<Job> atom_pop_from_jobQue();
}//---------------------- namespace: esrc -------------------------//
#endif
|
turesnake/tprPixelGames | src/Engine/ecoSys/GoSpecData.h | <reponame>turesnake/tprPixelGames<gh_stars>100-1000
/*
* ========================= GoSpecData.h =======================
* -- tpr --
* CREATE -- 2019.09.13
* MODIFY --
* ----------------------------------------------------------
*/
#ifndef TPR_GO_SPEC_DATA_H
#define TPR_GO_SPEC_DATA_H
//-------------------- CPP --------------------//
#include <vector>
//------------------- Engine --------------------//
#include "GameObjType.h"
#include "GoAssemblePlan.h"
//--------------- Script ------------------//
//-- 仅用于 ecoObj -> create a go
// 这个名字太糟糕了,应该被修改
// 在未来,它可能跟随 整个旧版 mp-go 分配系统 被取消
class GoSpecData{
public:
GoSpecData( goSpeciesId_t rootGoSpeciesId_,
const std::string &afsName_,
goLabelId_t goLabelId_):
rootGoSpeciesId(rootGoSpeciesId_),
afsName(afsName_),
goLabelId(goLabelId_)
{}
//----- get -----//
inline goSpeciesId_t get_rootGoSpeciesId()const noexcept{ return this->rootGoSpeciesId; }
inline const std::string &get_afsName()const noexcept{ return this->afsName; }
inline const std::string &get_animLabel()const noexcept{ return this->animLabel; }
inline goLabelId_t get_goLabelId()const noexcept{
return this->goLabelId;
}
private:
goSpeciesId_t rootGoSpeciesId {};
std::string afsName {};
std::string animLabel {};
goLabelId_t goLabelId {};
};
#endif
|
turesnake/tprPixelGames | src/Engine/input/JoystickButton_2_GameKey_map.h | /*
* ================= JoystickButton_2_GameKey_map.h ==========================
* -- tpr --
* CREATE -- 2020.01.29
* MODIFY --
* ----------------------------------------------------------
* only include by input.cpp
* ---
*/
#ifndef TPR_JOYSTICK_BUTTON_2_GAMEKEY_MAP_H
#define TPR_JOYSTICK_BUTTON_2_GAMEKEY_MAP_H
#include <unordered_map>
#include "Joystick.h"
#include "GameKey.h"
// 按键映射表
// 键值完全一致的表
inline std::unordered_map<Joystick::Button, GameKey> JoystickButton_2_GameKey_map{
{Joystick::Button::A, GameKey::A},
{Joystick::Button::B, GameKey::B},
{Joystick::Button::X, GameKey::X},
{Joystick::Button::Y, GameKey::Y},
{Joystick::Button::LB, GameKey::LB},
{Joystick::Button::RB, GameKey::RB},
{Joystick::Button::Back, GameKey::Back},
{Joystick::Button::Start, GameKey::Start},
{Joystick::Button::Guide, GameKey::Guide},
{Joystick::Button::LeftThumb, GameKey::LeftThumb},
{Joystick::Button::RightThumb, GameKey::RightThumb},
{Joystick::Button::Hat_Up, GameKey::Hat_Up},
{Joystick::Button::Hat_Right, GameKey::Hat_Right},
{Joystick::Button::Hat_Down, GameKey::Hat_Down},
{Joystick::Button::Hat_Left, GameKey::Hat_Left}
};
#endif
|
turesnake/tprPixelGames | src/Engine/random/GameSeed.h | /*
* ====================== GameSeed.h =======================
* -- tpr --
* CREATE -- 2019.02.23
* MODIFY --
* ----------------------------------------------------------
* game seed for random
* ----------------------------
*/
#ifndef TPR_GameSeed_H
#define TPR_GameSeed_H
//--- glm - 0.9.9.5 ---
#include "glm_no_warnings.h"
//------------------- CPP --------------------//
#include <cstdint> // uint8_t
//-------------------- Engine --------------------//
#include "random.h"
#include "IntVec.h"
//- singleton --
// 一个存档只有一个 gameSeed 实例 --
// 具体的 随机引擎和分布器,则由各模块自行包含 (tmp)
class GameSeed{
public:
GameSeed()=default;
void init( uint32_t baseSeed_ );
inline std::default_random_engine &getnc_realRandEngine()noexcept{ return this->realRandEngine; }
inline const glm::dvec2 &get_altiSeed_pposOffSeaLvl() const noexcept{ return this->altiSeed_pposOffSeaLvl; }
inline const glm::dvec2 &get_altiSeed_pposOffBig() const noexcept{ return this->altiSeed_pposOffBig; }
inline const glm::dvec2 &get_altiSeed_pposOffMid() const noexcept{ return this->altiSeed_pposOffMid; }
inline const glm::dvec2 &get_altiSeed_pposOffSml() const noexcept{ return this->altiSeed_pposOffSml; }
inline const glm::dvec2 &get_densitySeed_pposOff() const noexcept{ return this->densitySeed_pposOff; }
inline const glm::dvec2 &get_field_dposOff() const noexcept{ return this->field_dposOff; }
inline const glm::dvec2 &get_chunk_dposOff() const noexcept{ return this->chunk_dposOff; }
inline const glm::dvec2 &get_ecoObjWeight_dposOff() const noexcept{ return this->ecoObjWeight_dposOff; }
inline std::default_random_engine &getnc_shuffleEngine()noexcept{
this->shuffleEngine.seed( GameSeed::fixedShuffleSeed ); // every time
return this->shuffleEngine;
}
//======== static ========//
static uint32_t apply_new_baseSeed()noexcept{ return get_new_seed(); }
private:
//======== vals ========//
uint32_t baseSeed {}; //-- 最基础的那颗种子,其它种子由它生成。
//- [-1000, 1000] 之间的 随机数
glm::dvec2 altiSeed_pposOffSeaLvl {};
glm::dvec2 altiSeed_pposOffBig {};
glm::dvec2 altiSeed_pposOffMid {};
glm::dvec2 altiSeed_pposOffSml {};
//- [-1000, 1000] 之间的 随机数 --
glm::dvec2 densitySeed_pposOff {};
//- [-1000.0, 1000.0] 之间的 随机数 --
glm::dvec2 field_dposOff {};
glm::dvec2 chunk_dposOff {};
glm::dvec2 ecoObjWeight_dposOff {};
//======== randEngine ========//
std::default_random_engine randEngine; //-通用 伪随机数引擎实例
std::default_random_engine realRandEngine; //-通用 真随机数引擎实例
//- 主用于 “无关静态世界” 的随机事件。比如 螃蟹刷怪笼 的分布。
// 每次生成都可以不一样
// 这个引擎会被外部 以任何次序和方式调用,所以它的值是彻底混乱的
std::default_random_engine shuffleEngine; //- 全局统一的 shuffle 用引擎
//======== flags ========//
bool is_all_seed_init {false};
void init_glm_vec2s();
//======== static ========//
static constexpr uint_fast32_t fixedShuffleSeed { 131 };
// shuffle 用引擎 使用全局统一 seed,每次用前都要初始化
// 素数,全局固定
};
#endif
|
turesnake/tprPixelGames | src/Engine/map/MapTexture.h | <reponame>turesnake/tprPixelGames
/*
* ====================== MapTexture.h =======================
* -- tpr --
* CREATE -- 2019.01.06
* MODIFY --
* ----------------------------------------------------------
* texture for map sys
* ----------------------------
*/
#ifndef TPR_MAP_TEXTURE_H
#define TPR_MAP_TEXTURE_H
//=== *** glad FIRST, glfw SECEND *** ===
// Don't include glfw3.h ALONE!!!
#include <glad/glad.h>
//-------------------- CPP --------------------//
#include <vector>
#include <functional>
//------------------- Engine --------------------//
#include "IntVec.h"
#include "config.h"
#include "RGBA.h"
//-1- bind MapTexture::mapBuilder
//-2- create MapTexture instance: mapTex
//-3- call mapTex.init();
class MapTexture{
public:
void creat_texName();
inline void delete_texture()noexcept{
glDeleteTextures( 1, &texName );
}
inline GLuint get_texName()const noexcept{ return texName; }
//- texBuf 数据 是在 job线程中生成的,传递到 主线程后,只需 swap 到此处 --
inline void swap_texBuf_from( std::vector<RGBA> &src_ )noexcept{
this->texBuf.swap(src_);
}
private:
GLuint texName {0}; //- texture textel_name
std::vector<RGBA> texBuf {}; //- 本模块的重心,一张合成的 texture
// 在生成 texName 之后,此数据可以被释放
// 若不选择释放,则存储在 本实例中,直到实例被销毁
};
#endif
|
turesnake/tprPixelGames | src/Engine/gameObj/PubBinaryValType.h | /*
* ==================== PubBinaryValType.h =====================
* -- tpr --
* CREATE -- 2019.02.03
* MODIFY --
* ----------------------------------------------------------
*
* ----------------------------
*/
#ifndef TPR_PUB_BINARY_VAL_TYPE_H
#define TPR_PUB_BINARY_VAL_TYPE_H
//-------------------- CPP --------------------//
#include <map>
#include <cstdint> // uint8_t
//- go.pubBinary 中 存储的变量 的类型
// 千万不能 自定义 元素的值。应该让元素的值按照持续,被自动分配(从0开始增长)
// 元素值将被转换为 idx,用来访问 bitMap
enum class PubBinaryValType : uint32_t{
HP, //- int
MP //- int
};
std::map<uint32_t, uint32_t> &get_PubBinaryValSizes();
#endif
|
turesnake/tprPixelGames | src/Engine/input/GameKey.h | <reponame>turesnake/tprPixelGames
/*
* ========================= GameKey.h ==========================
* -- tpr --
* CREATE -- 2019.02.13
* MODIFY --
* ----------------------------------------------------------
* 游戏按键
* ----------------------------
*/
#ifndef TPR_GAME_KEY_H
#define TPR_GAME_KEY_H
// 游戏程序内部,对 input按键的 类型识别
// 数据存储在 InputINS 实例中
// ---
// 完全参照 joystick 按键顺序排布
// 或者是,标准 joystick 支持哪些按键,本游戏就支持哪些按键
enum class GameKey : int {
A = 0,
B,
X,
Y,
LB,
RB,
Back,
Start,
Guide,
LeftThumb,
RightThumb,
Hat_Up,
Hat_Right,
Hat_Down,
Hat_Left,
};
#endif
|
turesnake/tprPixelGames | src/Engine/gameObj/goDataForCreate/assemble_go.h | /*
* ======================= assemble_go.h =====================
* -- tpr --
* CREATE -- 2020.02.21
* MODIFY --
* ----------------------------------------------------------
*/
#ifndef TPR_ASSEMBLE_GO_H
#define TPR_ASSEMBLE_GO_H
//-------------------- Engine --------------------//
//...
// need
class GameObj;
class DyParam;
class GoDataForCreate;
const GoDataForCreate *assemble_regularGo( GameObj &goRef_,const DyParam &dyParams_ );
const GoDataForCreate *assemble_regularGo( GameObj &goRef_, const GoDataForCreate *goDataPtr_ );
#endif
|
turesnake/tprPixelGames | src/Engine/collision/signInMapEnts/SignInMapEnts_Square.h | <gh_stars>100-1000
/*
* ====================== SignInMapEnts_Square.h ==========================
* -- tpr --
* CREATE -- 2020.02.19
* MODIFY --
* ----------------------------------------------------------
*/
#ifndef TPR_SIGN_IN_MAP_ENTS_SQUARE_H
#define TPR_SIGN_IN_MAP_ENTS_SQUARE_H
#include "pch.h"
//--------------- Engine ------------------//
#include "SignInMapEnts_Square_Type.h"
class SignInMapEnts_Square{
public:
inline const std::vector<IntVec2> &get_all_mapEntOffs()const noexcept{ return this->mapEntOffs; }
inline const glm::dvec2 &get_rootMapEntMid_2_rootAnchor_dposOff()const noexcept{ return this->rootMapEntMid_2_rootAnchor_dposOff; }
static inline const SignInMapEnts_Square &get_signInMapEnts_square_ref( SignInMapEnts_Square_Type type_ )noexcept{
tprAssert( SignInMapEnts_Square::dataUPtrs.find(type_) != SignInMapEnts_Square::dataUPtrs.end() );
return *SignInMapEnts_Square::dataUPtrs.at(type_);
}
static void init_for_static()noexcept; // MUST CALL IN MAIN !!!
private:
SignInMapEnts_Square()=default;
static inline SignInMapEnts_Square &insert_new_signInMapEnts_square( SignInMapEnts_Square_Type type_ )noexcept{
std::unique_ptr<SignInMapEnts_Square> uptr ( new SignInMapEnts_Square() ); // can't use std::make_unique
auto [insertIt, insertBool] = SignInMapEnts_Square::dataUPtrs.emplace( type_, std::move(uptr) );
tprAssert( insertBool );
return *(insertIt->second);
}
//-------- vals --------//
std::vector<IntVec2> mapEntOffs {};
// 每个 squGo,恒定拥有一个 rootMP (off={0,0}
// 以及 0~n 个 weakMP
glm::dvec2 rootMapEntMid_2_rootAnchor_dposOff {};
// 加上 rootMPMidDPos, 可以计算出 go rootAnchor 所在点。(也就是 goDPos 位置)
// ---
// rootMP 往往不能成为 整组 multiMP 的正中心位置(偏向右上角)
//======= static =======//
static std::unordered_map<SignInMapEnts_Square_Type, std::unique_ptr<SignInMapEnts_Square>> dataUPtrs;
};
#endif
|
turesnake/tprPixelGames | src/Engine/input/input.h | /*
* ========================= input.h ==========================
* -- tpr --
* CREATE -- 2019.01.05
* MODIFY --
* ----------------------------------------------------------
* 键盘,鼠标,joystick 等输入设备 管理文件
* ----------------------------
*/
#ifndef TPR_INPUT_H
#define TPR_INPUT_H
//=== *** glad FIRST, glfw SECEND *** ===
// Don't include glfw3.h ALONE!!!
#include<glad/glad.h>
#include<GLFW/glfw3.h>
//-------------------- CPP --------------------//
#include <functional>
//-------------------- Engine --------------------//
#include "IntVec.h"
#include "InputINS.h"
namespace input{//------------- namespace input --------------------
using F_InputINS_Handle = std::function< void(const InputINS&) >;
//-- 外部通过这个函数,来绑定需要的 inputINS 处理函数 --
void bind_inputINS_handleFunc( const F_InputINS_Handle &_func );
void InputInit_for_begin(); // 仅适用于 scene:begin
void processInput( GLFWwindow *windowPtr_ );
IntVec2 get_mouse_pos();
}//----------------- namespace input: end -------------------
#endif
|
turesnake/tprPixelGames | src/Engine/collision/Collision.h | /*
* ======================= Collision.h ==========================
* -- tpr --
* CREATE -- 2019.09.01
* MODIFY --
* ----------------------------------------------------------
*/
#ifndef TPR_COLLISION_2_H
#define TPR_COLLISION_2_H
#include "pch.h"
//-------------------- CPP --------------------//
#include <utility> //pair
#include <variant>
//-------------------- Engine --------------------//
#include "ColliderType.h"
#include "GameObjPos.h"
#include "GameObjType.h"
#include "SignInMapEnts_Circle.h"
#include "NineDirection.h"
#include "SignInMapEnts_Square_Type.h"
#include "mapEntKey.h"
//--- need ---//
class GameObj;
//-- 存在两种碰撞检测:
// --1-- 移动碰撞检测
// --2-- 技能碰撞检测
// 这两种 相互独立。并行存在
// 这意味着,go并不需要停下来才能 释放技能。
// 当然,由于 动画制作的问题,大部分技能在施展期间,还是会强制停下 go 的移动
class Collision{
using F_get_colliPointDPosOffsRef = std::function<const std::vector<glm::dvec2> &()>;
using F_is_extraPassableDogoSpeciesId = std::function<bool(goSpeciesId_t)>; // param: dogoSpeciesId
public:
explicit Collision( GameObj &goRef_ ):
goRef(goRef_)
{}
glm::dvec2 detect_moveCollide( const glm::dvec2 &moveVec_ ); // tmp
//-- only call in go init --
inline void init_signInMapEnts_circle( const glm::dvec2 &newGoDPos_, F_get_colliPointDPosOffsRef func_1_ )noexcept{
this->signInMapEnts_cir_uptr = std::make_unique<SignInMapEnts_Circle>( newGoDPos_, func_1_ );
}
inline void set_isDoPass( bool val_ )noexcept{ this->isDoPass = val_; }
inline void set_isBePass( bool val_ )noexcept{ this->isBePass = val_; }
inline bool get_isDoPass()const noexcept{ return this->isDoPass; }
// bego pass 检测其实存在 2步:
// isBePass == true: 允许一切 dogo 穿过
// isBePass == false: 若 dogo 为少数登记类型,也可以穿过
// 剩余的 dogo 才会被禁止穿过
inline bool get_isBePass( goSpeciesId_t dogoSpeciesId_ )const noexcept{
if( this->isBePass ){
return true;
}
return (this->Is_extraPassableDogoSpeciesId != nullptr) ?
this->Is_extraPassableDogoSpeciesId(dogoSpeciesId_) :
false;
}
inline void set_functor_Is_extraPassableDogoSpeciesId( F_is_extraPassableDogoSpeciesId functor_ )noexcept{
this->Is_extraPassableDogoSpeciesId = functor_;
}
inline const std::set<IntVec2> &get_current_signINMapEnts_circle_ref()const noexcept{
return this->signInMapEnts_cir_uptr->get_currentSignINMapEntsRef();
}
static void init_for_static()noexcept; // MUST CALL IN MAIN !!!
private:
std::pair<bool, glm::dvec2> collect_AdjacentBegos_and_deflect_moveVec( const glm::dvec2 &moveVec_ );
std::pair<bool, glm::dvec2> collect_IntersectBegos_and_truncate_moveVec( const glm::dvec2 &moveVec_ );
void reSignUp_dogo_to_chunk_and_mapents( const glm::dvec2 &moveVec_ )noexcept;
//======== vals ========//
GameObj &goRef;
// 仅被 cir-dogo 使用
std::unique_ptr<SignInMapEnts_Circle> signInMapEnts_cir_uptr {nullptr};
//======== flags ========//
bool isDoPass {false};//- 当自己为 主动go 时,是否穿过 被动go;
// 如果本go 是 “穿透箭”。可将此值设置为 true
// 此时,本go 将无视 被动go 的状态,移动穿过一切 被动go
bool isBePass {false};//- 当自己为 被动go 时,是否允许 主动go 穿过自己;
// 如果本go 是 “草”/“腐蚀液”,可将此值 设置为 true
// 此时,本go 将允许任何 go 从自己身上 穿过
F_is_extraPassableDogoSpeciesId Is_extraPassableDogoSpeciesId {nullptr};
// 当 bego.isBePass == false 时,
// 将额外允许一组特殊的 dogo 穿过自己
// 比如,只有 “鸡”,可以穿过 “鸡笼”
// 推荐用法:
//-- 对于 草这种允许被dogo穿过,自己又无法移动的。 isBePass=true, isDoPass 随意(无效)
//-- 对于 常规生物,2值都设置为 false
//-- 对于 允许别人穿过自己,但自己无法穿透任意墙壁的 dogo,类似 mc中的羊,isDoPass=false, isBePass=true
// 一些小动物,npc 特别适合这种
//-- 对于 带穿透属性的 箭矢,isDoPass=true, isBePass 随意(无效)
//===== static =====//
static void build_a_scanBody( const glm::dvec2 &moveVec_,
const glm::dvec2 &dogoDPos_ );
static std::vector<glm::dvec2> obstructNormalVecs;
// moveCollide 第一阶段,在 dogo起始位置,所有与之 相邻 的bego,
// 对 dogo 施与的 阻挡法向量集(墙壁法向量集)
// 用来修正 moveVec
static std::set<NineDirection> confirmedAdjacentMapEnts;
// 确认会发生 碰撞的 相邻 mapents [0,2]
static std::unordered_map<goid_t, glm::dvec2> adjacentCirBeGos; // 相邻关系的 cir_begos
// --1-- begoid
// --2-- obstructNormalVec
// 相邻go 是触发 ”滑动式位移“ 的唯一途径
static std::unordered_set<goid_t> begoids_circular;
static std::unordered_set<goid_t> begoids;
//- 从 signInMapEnts 中收集的 半有效 begoids
static std::vector<IntVec2> mapEnts_in_scanBody;
// 用于 squ_begos 碰撞检测
// 与 粗略扫掠体 相交的 mapents
static std::multiset<double> tVals;
//- 确认发生碰撞的 begos,将被收集起来,按照 t 值排序
};
#endif
|
turesnake/tprPixelGames | src/Engine/sys/global.h | /*
* ========================= global.h ==========================
* -- tpr --
* CREATE -- 2018.11.21
* MODIFY --
* ----------------------------------------------------------
* 全局变量
* 使用 cpp 特有的 inline 关键词来 一步到位地 声明+初始化
* ----------------------------
*/
#ifndef TPR_GLOBAL_H
#define TPR_GLOBAL_H
//-------------------- CPP --------------------//
#include <string>
//inline bool is_fst_run {}; //-- 本次运行,是否为 本进程编译后的 首次运行
//-- 每次运行时,由函数 check_fst_run() 设置
//-- 若为 true, 是 首次运行
//-- 若为 false, 不是 首次运行
//----------------------------------------------------//
// file
//----------------------------------------------------//
extern int fd_cwd; //-- 项目 主目录 fd
extern std::string path_cwd; //-- exe 所在目录的 path
extern std::string path_dataBase; //-- .../build/publish/dataBase/
extern std::string path_shaders; //-- .../build/publish/shaders/
//extern std::string path_textures; //-- .../build/publish/textures/ // 暂未被使用 ...
extern std::string path_jsons; //-- .../build/publish/jsons/
extern std::string path_tprLog; //-- .../build/publish/tprLog/
extern std::string path_blueprintDatas; //-- .../build/publish/blueprintDatas/
extern std::string path_gameObjDatas; //-- .../build/publish/gameObjDatas/
//----------------------------------------------------//
// OS
//----------------------------------------------------//
//-- 当前身处什么 操作系统 --//
#define OS_NULL 0
#define OS_APPLE 1
#define OS_UNIX 2
#define OS_WIN32 3
extern int current_OS;
#endif
|
turesnake/tprPixelGames | src/Engine/resource/esrc_camera.h | /*
* ========================= esrc_camera.h ==========================
* -- tpr --
* CREATE -- 2019.04.19
* MODIFY --
* ----------------------------------------------------------
*/
#ifndef TPR_ESRC_CAMERA_H
#define TPR_ESRC_CAMERA_H
//-------------------- Engine --------------------//
#include "Camera.h"
namespace esrc {//------------------ namespace: esrc -------------------------//
void init_camera();
Camera &get_camera();
}//---------------------- namespace: esrc -------------------------//
#endif
|
turesnake/tprPixelGames | src/Engine/mesh/GameObjMeshSet.h | /*
* ===================== GameObjMeshSet.h ==========================
* -- tpr --
* CREATE -- 2020.03.07
* MODIFY --
* ----------------------------------------------------------
*/
#ifndef TPR_GAME_OBJ_MESH_SET_H
#define TPR_GAME_OBJ_MESH_SET_H
//-------------------- Engine --------------------//
#include "GameObjMesh.h"
#include "ShaderType.h"
class GameObjMeshSet{
public:
using F_callback = std::function<void(GameObjMesh&)>;
class Data{
public:
Data( std::unique_ptr<GameObjMesh> uptr_ ):
goMesh(std::move(uptr_)),
callback_inLastFrame(nullptr),
callback_everyFrame(nullptr),
goMeshPvtDataPtr( this->goMesh->get_animActionPvtDataPtr() )
{}
//------------//
std::unique_ptr<GameObjMesh> goMesh;
F_callback callback_inLastFrame;
F_callback callback_everyFrame;
const AnimAction::PvtData *goMeshPvtDataPtr;
};
GameObjMeshSet( GameObj &goRef_ ):
goRef(goRef_)
{}
GameObjMesh &creat_new_goMesh(
const std::string &name_,
animSubspeciesId_t subspeciesId_,
AnimActionEName actionEName_,
RenderLayerType layerType_,
ShaderType shaderType_,
const glm::vec2 pposOff_ = glm::vec2{0.0,0.0},
double zOff_ = 0.0,
size_t uWeight = 1051, // 素数
bool isVisible_ = true
);
// 暂时仅支持 特定位置的 callback
inline void bind_goMesh_callback_inLastFrame( const std::string &name_, F_callback callback_ )noexcept{
tprAssert( this->goMeshs.find(name_) != this->goMeshs.end() );
this->goMeshs.at(name_)->callback_inLastFrame = callback_;
}
inline void bind_goMesh_callback_everyFrame( const std::string &name_, F_callback callback_ )noexcept{
tprAssert( this->goMeshs.find(name_) != this->goMeshs.end() );
this->goMeshs.at(name_)->callback_everyFrame = callback_;
}
inline void render_all_goMeshs_with_callback()noexcept{
auto it = this->goMeshs.begin();
while( it != this->goMeshs.end() ){
auto &[name, dataUPtr] = *it;
// 需要被删除的 gomesh,会在前一帧被设置 flag,
// 并且在后一帧(本帧)查询 并正式删除
if( dataUPtr->goMesh->get_isNeedToBeErase() ){
it = this->goMeshs.erase( it ); // saft way
continue; // MUST
}
if( dataUPtr->callback_everyFrame ){
dataUPtr->callback_everyFrame( *(dataUPtr->goMesh) );
}
if(dataUPtr->goMeshPvtDataPtr->isLastFrame){
if( dataUPtr->callback_inLastFrame ){
dataUPtr->callback_inLastFrame( *(dataUPtr->goMesh) );
}
}
dataUPtr->goMesh->RenderUpdate_auto();
//===//
it++; // MUST
}
}
// 即便设置了 callback. 也不会被执行
// 也不执行自动 erase
inline void render_all_goMeshs_without_callback()noexcept{
for( auto &[name, dataUPtr] : this->goMeshs ){
dataUPtr->goMesh->RenderUpdate_auto();
}
}
inline void render_all_groundGoMesh()noexcept{
for( auto &[name, dataUPtr] : this->goMeshs ){
dataUPtr->goMesh->RenderUpdate_in_fast_way();
}
}
inline void render_all_floorGoMesh()noexcept{
for( auto &[name, dataUPtr] : this->goMeshs ){
dataUPtr->goMesh->RenderUpdate_in_fast_way();
}
}
inline GameObjMesh &get_goMeshRef( const std::string &name_ )noexcept{
tprAssert( this->goMeshs.find(name_) != this->goMeshs.end() );
return *(this->goMeshs.at(name_)->goMesh);
}
inline std::unordered_map<std::string, std::unique_ptr<GameObjMeshSet::Data>> &get_goMeshs()noexcept{ return this->goMeshs; }
private:
GameObj &goRef;
// - rootGoMesh -- name = “root”; 核心goMesh;
// - childGoMesh -- 剩下的goMesh,名字随意
std::unordered_map<std::string, std::unique_ptr<GameObjMeshSet::Data>> goMeshs {};
//- go实例 与 GoMesh实例 强关联
// 大部分go不会卸载/增加自己的 GoMesh实例
//- 在一个 具象go类实例 的创建过程中,会把特定的 GoMesh实例 存入此容器
//- 只存储在 mem态。 在go实例存入 硬盘时,GoMesh实例会被丢弃
//- 等再次从section 加载时,再根据 具象go类型,生成新的 GoMesh实例。
};
#endif
|
turesnake/tprPixelGames | src/Engine/camera/RenderLayerType.h | <gh_stars>100-1000
/*
* ========================= RenderLayerType.h ==========================
* -- tpr --
* CREATE -- 2019.01.22
* MODIFY --
* ----------------------------------------------------------
* render layer
* ----------------------------
*/
#ifndef TPR_RENDER_LAYER_H
#define TPR_RENDER_LAYER_H
#include <string>
// from zFar -> zNear
enum class RenderLayerType{
Ground,
GroundGo,
Floor,
BioSoup, // 深度区间 和 MajorGoes 一样大
GoShadows,
Debug,
MajorGoes,
AboveMajorGoes,
//....
UIs
};
std::string renderLayerType_2_str( RenderLayerType dir_ )noexcept;
RenderLayerType str_2_renderLayerType( const std::string &str_ )noexcept;
#endif
|
turesnake/tprPixelGames | src/Engine/animFrameSet/AnimFrameSet.h | <gh_stars>100-1000
/*
* =================== AnimFrameSet.h ==========================
* -- tpr --
* CREATE -- 2018.11.23
* MODIFY --
* ----------------------------------------------------------
* 存储一个 动画动作 的所有 帧text names
* 以及每一帧 的 投影单位集
* 本游戏只支持 png 图片格式。
* -----------------
* 一个完整的 动画动作, 会被存储为 3 种 png 图片。
* 图片名字格式为:
* dog_ack_01.P.png (画面)
* dog_ack_01.J.png (投影)
* dog_ack_01.S.png (阴影)
* 格式拆分如下:
* dog_ack_01 --- 真正的名字,记录到 name 中
* P / J / S --- P==画面, J==投影, S==阴影
* -----------------
* texture 管理:
* gl中,texture资源的唯一限制在于 显存大小。
* 所以,在目前版本中,假定显存无限大,
* 将游戏的所有 texture资源 一股脑存入 显存中
* (等正式爆发 显存危机了,再做调整...)
* ---
* 随着 tex动态生成器的 引入,texture 的数量将呈爆炸态
* 此时就有必要进入 更为完善的 tex显存管理(到时再说)
* ----------------------------
*/
#ifndef TPR_ANIM_FRAME_SET_H
#define TPR_ANIM_FRAME_SET_H
//=== *** glad FIRST, glfw SECEND *** ===
// Don't include glfw3.h ALONE!!!
#include <glad/glad.h>
#include "pch.h"
//-------------------- Engine --------------------//
#include "RGBA.h"
#include "AnimActionPos.h"
#include "AnimAction.h"
#include "AnimSubspecies.h"
using afsId_t = uint32_t; //- animFrameSet id type
class AnimFrameSet{
public:
explicit AnimFrameSet( const std::string &name_ ):
name(name_)
{}
void insert_a_png(
const std::string &path_pic_,
IntVec2 frameNum_,
size_t totalFrameNum_,
bool isHaveShadow_,
bool isPjtSingleFrame_,
bool isShadowSingleFrame_,
const std::vector<std::shared_ptr<AnimActionParam>> &animActionParams_ );
inline const std::vector<GLuint> *get_texNames_pic_ptr() const noexcept{
return &(this->texNames_pic);
}
inline const std::vector<GLuint> *get_texNames_shadow_ptr() const noexcept{
return &(this->texNames_shadow);
}
inline animSubspeciesId_t apply_a_random_animSubspeciesId(const std::string &label_, size_t uWeight_ )noexcept{
return this->subGroup.apply_a_random_animSubspeciesId( label_, uWeight_ );
}
private:
void handle_pjt( const std::vector<std::shared_ptr<AnimActionParam>> &animActionParams_ );
void handle_shadow();
//======== vals ========//
//-- 通常为 图元所属的 obj name --
std::string name; //-- 目前来看 用处不大
//- 动画中的每一帧图都会被 存储为 一个 texture实例。
//- 具体数据存储在 gl内。 此处存储其 textel names
//- 帧排序 符合 左上坐标系(也就是我们排列动画帧的坐标系) --
std::vector<GLuint> texNames_pic {};
std::vector<GLuint> texNames_shadow {}; //- 就算没有 shadow数据,也要填写0 来占位
//-- each animaction --
std::unordered_map<animActionPosId_t, std::unique_ptr<AnimActionPos>> animActionPosUPtrs {};
AnimSubspeciesGroup subGroup {};
//======== flags ========//
bool isPJTSingleFrame {false}; //- Jpng 是否只有一帧
//- 若为 true,本afs实例下属的所有 animAction,
// 都直接绑定这唯一的一份 AnimActionPos 数据
bool isShadowSingleFrame {false}; //- Spng 是否只有一帧
};
namespace json{//------------- namespace json ----------------
void parse_animFrameSetJsonFile();
// go 相关的 afs数据,应该被 各个 go 独立管理,
// 不再由此函数 统一加载
void parse_single_animFrameSetJsonFile( const std::string &path_file_,
std::unordered_set<std::string> *out_afsNamesPtr_=nullptr );
}//------------- namespace json: end ----------------s
#endif
|
turesnake/tprPixelGames | src/Script/gameObjs/majorGos/chicken/Chicken.h | <gh_stars>100-1000
/*
* ========================= Chicken.h ==========================
* -- tpr --
* CREATE -- 2020.01.07
* MODIFY --
* ----------------------------------------------------------
*
* ----------------------------
*/
#ifndef TPR_GO_CHICKEN_H
#define TPR_GO_CHICKEN_H
//-------------------- Engine --------------------//
#include "GameObj.h"
#include "DyParam.h"
namespace gameObjs{//------------- namespace gameObjs ----------------
class Chicken{
public:
//--- 延迟init ---//
static void init(GameObj &goRef_, const DyParam &dyParams_ );
private:
static void bind( GameObj &goRef_ );
static void rebind( GameObj &goRef_ );
//--- callback ---//
static void OnRenderUpdate( GameObj &goRef_ );
static void OnLogicUpdate( GameObj &goRef_ );
static void OnActionSwitch( GameObj &goRef_, ActionSwitchType type_ );
//--- oth ---//
static void moveState_manage( GameObj &goRef_,
GameObjMesh &goMeshRef_
)noexcept;
static void move_AnimAction_switch( GameObj &goRef_ );
};
}//------------- namespace gameObjs: end ----------------
#endif
|
turesnake/tprPixelGames | src/Engine/resource/esrc_coordinate.h | <filename>src/Engine/resource/esrc_coordinate.h
/*
* ========================= esrc_coordinate.h ==========================
* -- tpr --
* CREATE -- 2019.11.15
* MODIFY --
* ----------------------------------------------------------
*/
#ifndef TPR_ESRC_COORDINATE_H
#define TPR_ESRC_COORDINATE_H
//-------------------- Engine --------------------//
#include "Coordinate.h"
namespace esrc {//------------------ namespace: esrc -------------------------//
void init_coordinate();
const Coordinate &get_worldCoordRef()noexcept;
}//---------------------- namespace: esrc -------------------------//
#endif
|
turesnake/tprPixelGames | src/Engine/tools/RGBA.h | /*
* ========================= RGBA.h ==========================
* -- tpr --
* CREATE -- 2018.12.26
* MODIFY --
* ----------------------------------------------------------
* png pix color: RGBA
* ----------------------------
*/
#ifndef TPR_RGBA_H
#define TPR_RGBA_H
#include "pch.h"
enum class RGBA_ChannelType : uint8_t {
R = 1,
G,
B,
A
};
//-- 1个 png 像素 的 data 结构 --
class RGBA{
public:
//---- constructor -----//
constexpr RGBA() = default;
constexpr RGBA( uint8_t r_, uint8_t g_, uint8_t b_, uint8_t a_ ):
r(r_),
g(g_),
b(b_),
a(a_)
{}
inline bool is_near( const RGBA &a_, uint8_t off_ )const noexcept {
int rr = static_cast<int>(this->r) - static_cast<int>(a_.r);
int gg = static_cast<int>(this->g) - static_cast<int>(a_.g);
int bb = static_cast<int>(this->b) - static_cast<int>(a_.b);
int aa = static_cast<int>(this->a) - static_cast<int>(a_.a);
return (
(std::abs(rr) <= static_cast<int>(off_)) &&
(std::abs(gg) <= static_cast<int>(off_)) &&
(std::abs(bb) <= static_cast<int>(off_)) &&
(std::abs(aa) <= static_cast<int>(off_))
);
}
//-- 支持更复杂的数据 累加 --
inline RGBA add( int r_, int g_, int b_, int a_ )const noexcept {
int rr = static_cast<int>(this->r) + r_;
int gg = static_cast<int>(this->g) + g_;
int bb = static_cast<int>(this->b) + b_;
int aa = static_cast<int>(this->a) + a_;
tprAssert( (rr>=0) && (rr<256) &&
(gg>=0) && (gg<256) &&
(bb>=0) && (bb<256) );
return RGBA { static_cast<uint8_t>(rr),
static_cast<uint8_t>(gg),
static_cast<uint8_t>(bb),
static_cast<uint8_t>(aa) };
}
inline std::string to_string()const noexcept{ // for debug
return fmt::format( "RGBA:{0},{1},{2},{3};", this->r, this->g, this->b, this->a );
}
//======== vals ========//
uint8_t r {0};
uint8_t g {0};
uint8_t b {0};
uint8_t a {255};
};
/* ===========================================================
* operator ==, !=
* -----------------------------------------------------------
*/
inline constexpr bool operator==( const RGBA &a_, const RGBA &b_ ) noexcept {
return ( (a_.r==b_.r) && (a_.g==b_.g) && (a_.b==b_.b) && (a_.a==b_.a) );
}
inline constexpr bool operator!=( const RGBA &a_, const RGBA &b_ ) noexcept {
return ( (a_.r!=b_.r) || (a_.g!=b_.g) || (a_.b!=b_.b) || (a_.a!=b_.a) );
}
/* ===========================================================
* operator +
* -----------------------------------------------------------
*/
inline constexpr RGBA operator + ( const RGBA &a_, const RGBA &b_ ) noexcept {
int rr = static_cast<int>(a_.r) + static_cast<int>(b_.r);
int gg = static_cast<int>(a_.g) + static_cast<int>(b_.g);
int bb = static_cast<int>(a_.b) + static_cast<int>(b_.b);
int aa = static_cast<int>(a_.a) + static_cast<int>(b_.a);
tprAssert( (rr<256) && (gg<256) && (bb<256) && (aa<256) );
return RGBA { static_cast<uint8_t>(rr),
static_cast<uint8_t>(gg),
static_cast<uint8_t>(bb),
static_cast<uint8_t>(aa) };
}
class HSV{
public:
double h {}; // [0.0,360.0] degree
double s {}; // [0.0,1.0] pct
double v {}; // [0.0,1.0] pct
};
/* 计算结果精度有限:
* -- h 存在 +- 2.0 以内的误差,当明度较低时,误差会变大
* -- s/v 存在 +- 0.2 以内的误差
*/
inline HSV rgb_2_hsv( RGBA in_){
double ir = static_cast<double>(in_.r) / 255.0; // [0.0, 1.0]
double ig = static_cast<double>(in_.g) / 255.0; // [0.0, 1.0]
double ib = static_cast<double>(in_.b) / 255.0; // [0.0, 1.0]
// ignore alpha
HSV out {};
double min {};
double max {};
double delta {};
//---
min = ir < ig ? ir : ig;
min = min < ib ? min : ib;
max = ir > ig ? ir : ig;
max = max > ib ? max : ib;
out.v = max; // v
delta = max - min;
if (delta < 0.00001)
{
out.s = 0.0;
out.h = 0.0; // undefined, maybe nan?
return out;
}
if( max > 0.0 ) { // NOTE: if Max is == 0, this divide would cause a crash
out.s = (delta / max); // s
} else {
// if max is 0, then r = g = b = 0
// s = 0, h is undefined
out.s = 0.0;
out.h = static_cast<double>(NAN); // its now undefined
return out;
}
if( ir >= max ) // > is bogus, just keeps compilor happy
out.h = ( ig - ib ) / delta; // between yellow & magenta
else
if( ig >= max )
out.h = 2.0 + ( ib - ir ) / delta; // between cyan & yellow
else
out.h = 4.0 + ( ir - ig ) / delta; // between magenta & cyan
out.h *= 60.0; // degrees
if( out.h < 0.0 )
out.h += 360.0;
return out;
}
namespace rgba {//-------- namespace: rgba --------------//
//-- 只要两个 RGBA 值 足够接近,就算命中 [-常用-] --
inline bool is_rgba_near( const RGBA &a_, const RGBA &b_, uint8_t off_ ) noexcept {
int rr = static_cast<int>(a_.r) - static_cast<int>(b_.r);
int gg = static_cast<int>(a_.g) - static_cast<int>(b_.g);
int bb = static_cast<int>(a_.b) - static_cast<int>(b_.b);
int aa = static_cast<int>(a_.a) - static_cast<int>(b_.a);
return (
(std::abs(rr) <= static_cast<int>(off_)) &&
(std::abs(gg) <= static_cast<int>(off_)) &&
(std::abs(bb) <= static_cast<int>(off_)) &&
(std::abs(aa) <= static_cast<int>(off_))
);
}
/* ===========================================================
* linear_blend
* -----------------------------------------------------------
* 将两个颜色 线性混合
* param: aPercent_ -- 颜色 a_ 占了多少百分比 [0.0, 1.0]
*/
inline RGBA linear_blend( const RGBA &a_, const RGBA &b_, double aPercent_ ) noexcept {
tprAssert( (aPercent_>=0.0) && (aPercent_<=1.0) );
double bPercent = 1.0 - aPercent_;
double r = static_cast<double>(a_.r)*aPercent_ + static_cast<double>(b_.r)*bPercent;
double g = static_cast<double>(a_.g)*aPercent_ + static_cast<double>(b_.g)*bPercent;
double b = static_cast<double>(a_.b)*aPercent_ + static_cast<double>(b_.b)*bPercent;
//-- 默认不处理 RGBA.a --
return RGBA { static_cast<uint8_t>(r),
static_cast<uint8_t>(g),
static_cast<uint8_t>(b),
255 };
}
/* 简易版 正片叠底
* 假设 a_.a 永远等于 255, 通过 参数 _bPercent,来调节 正片叠底 程度
* param: bPercent_ -- 正片叠底 的 程度 [0.0, 1.0]
*/
inline RGBA multiply( const RGBA &a_, const RGBA &b_, double bPercent_ ) noexcept {
tprAssert( (bPercent_>=0.0) && (bPercent_<=1.0) );
double r = static_cast<double>(a_.r) * static_cast<double>(b_.r) / 255.0;
double g = static_cast<double>(a_.g) * static_cast<double>(b_.g) / 255.0;
double b = static_cast<double>(a_.b) * static_cast<double>(b_.b) / 255.0;
return rgba::linear_blend( a_,
RGBA { static_cast<uint8_t>(r),
static_cast<uint8_t>(g),
static_cast<uint8_t>(b),
255 },
(1.0-bPercent_) );
}
}//------------- namespace: rgba end --------------//
#endif
|
turesnake/tprPixelGames | src/Engine/random/random.h | /*
* ========================= random.h ==========================
* -- tpr --
* CREATE -- 2018.11.29
* MODIFY --
* ----------------------------------------------------------
* 随机数 模块
* ----------------------------
*/
#ifndef TPR_RANDOM_H
#define TPR_RANDOM_H
//------------------- CPP --------------------//
#include <random>
//------------------- Engine --------------------//
#include "tprCast.h"
#include "tprAssert.h"
#include "IntVec.h"
std::default_random_engine &get_dRandEng();
uint32_t get_new_seed();
// perlinNoise 往往不够均匀,更容易分布在中线周围
// 执行一次 取模运算,生成一组更均匀的 随机数
//-- param:
// noise_: [-1.0, 1.0]
// scale_: [0.0, 100000.0]
// modBase: some prime number [0, 10000]
inline size_t blender_the_perlinNoise( double noise_,
double scale_,
size_t modBase_ ){
tprAssert( (noise_>=-1.0) && (noise_<=1.0) &&
(scale_>0.0) &&
(scale_ > static_cast<double>(modBase_) * 2.0) );
double weight = (noise_+1.0) * scale_ + 76123.79; // [0.0, scale_*2.0]
size_t neo = cast_2_size_t(floor(weight)) % modBase_;
return neo; // [0, modBase_]
}
size_t calc_simple_mapent_uWeight( IntVec2 mpos_ )noexcept;
#endif
|
turesnake/tprPixelGames | src/Engine/map/Chunk.h | /*
* ========================== Chunk.h =======================
* -- tpr --
* CREATE -- 2018.12.09
* MODIFY --
* ----------------------------------------------------------
* Chunk 64*64_mapents, [left-bottom]
* ----------------------------
*/
#ifndef TPR_CHUNK_H
#define TPR_CHUNK_H
#include "pch.h"
//-------------------- Engine --------------------//
#include "MapEnt.h"
#include "GameObjType.h"
#include "fieldKey.h"
#include "chunkKey.h"
#include "MapCoord.h"
#include "sectionKey.h"
//-- 64*64 个 mapEnt, 组成一张 chunk [mem] --
// chunk 作为一个整体被存储到硬盘,就像 mc 中的 Field
class Chunk{
public:
explicit Chunk( chunkKey_t chunkKey_ ):
chunkKey(chunkKey_),
mpos(chunkKey_2_mpos(chunkKey_))
{
this->init();
}
inline void insert_2_goIds( goid_t id_ )noexcept{ this->goIds.insert(id_); }
inline size_t erase_from_goIds( goid_t id_ )noexcept{ return this->goIds.erase(id_); }
inline void insert_2_edgeGoIds( goid_t id_ )noexcept{ this->edgeGoIds.insert(id_); }
inline size_t erase_from_edgeGoIds( goid_t id_ )noexcept{ return this->edgeGoIds.erase(id_); }
//------- get -------//
inline IntVec2 get_mpos() const noexcept{ return this->mpos; }
inline chunkKey_t get_key() const noexcept{ return this->chunkKey; }
inline const std::set<goid_t> &get_goIds() const noexcept{ return this->goIds; }
inline const std::set<goid_t> &get_edgeGoIds() const noexcept{ return this->edgeGoIds; }
//-- 确保 参数为 基于chunk左下ent 的 相对mpos
inline MemMapEnt *getnc_mapEntPtr( const IntVec2 &lMPosOff_ )noexcept{
tprAssert( (lMPosOff_.x>=0) && (lMPosOff_.y>=0) );
size_t idx = cast_2_size_t( lMPosOff_.y * ENTS_PER_CHUNK<> + lMPosOff_.x );
tprAssert( idx < this->memMapEnts.size() ); //- tmp
return this->memMapEnts.at(idx).get();
}
private:
void init();
//========== vals ==========//
chunkKey_t chunkKey;
IntVec2 mpos; // [left-bottom]
size_t uWeight {}; // [0, 9999]
//--------------//
std::vector<std::unique_ptr<MemMapEnt>> memMapEnts {};
std::set<goid_t> goIds {}; //- 动态存储 本chunk 拥有的所有 go id。
// 部分元素会与 edgeGoIds 重合
// 添加和 释放工作要做干净。
std::set<goid_t> edgeGoIds {}; //- "临界go"/“边缘go” 容器
// 有些 go 位于 chunk边缘,其 collients 可能在隔壁 chunk
// 这种go 在 创建/销毁 阶段往往很麻烦
// 使用一个容器来 动态保管它们。
//======== flags ========//
bool is_dirty {false};//- 如果目标chunk上的 伪随机go数据,发生变化
//- 则被释放为 dirty.
// 下次生成此chunk时,不能直接使用 伪随机数,
// 还要参考 改动表 中的数据
// 此部分功能未实现
};
#endif
|
turesnake/tprPixelGames | src/Script/gameObjs/bioSoup/BioSoupColor.h | /*
* ====================== BioSoupColor.h ==========================
* -- tpr --
* CREATE -- 2020.03.10
* MODIFY --
* ----------------------------------------------------------
*/
#ifndef TPR_BIO_SOUP_COLOR_H
#define TPR_BIO_SOUP_COLOR_H
#include "pch.h"
#include <utility>
//-------------------- Engine --------------------//
#include "FloatVec.h"
namespace gameObjs::bioSoup {//------------- namespace gameObjs::bioSoup ----------------
class Color {
public:
constexpr Color()=default;
constexpr Color( const FloatVec3 &light_,
const FloatVec3 &mid_,
const FloatVec3 &dark_ ):
light(light_),
mid(mid_),
dark(dark_)
{}
// param: pct_ (0, 1.0)
// return:
// true - do close
// false - already close enough, do nothing
inline bool close_to( const Color &target_, float pct_ )noexcept{
FloatVec3 lOff = target_.light - this->light;
FloatVec3 mOff = target_.mid - this->mid;
FloatVec3 dOff = target_.dark - this->dark;
constexpr FloatVec3 zero { 0.0f, 0.0f, 0.0f };
//--
if( is_closeEnough( lOff, zero, 0.01f ) &&
is_closeEnough( mOff, zero, 0.01f ) &&
is_closeEnough( dOff, zero, 0.01f ) ){
return false; // close enough
}
// do close
this->light += lOff * pct_;
this->mid += mOff * pct_;
this->dark += dOff * pct_;
return true;
}
//===//
FloatVec3 light;
FloatVec3 mid;
FloatVec3 dark;
};
class ColorNode {
public:
const Color *colorPtr {};
float closePct {}; // 从任何颜色,接近本 node color 的接近率 (0.0f, 1.0f)
};
// 一组循环流动的 颜色信息,
// 当 diosoup 进入一种 chain 实例,就会停留在里面,循环播放这些颜色
class ColorNodeChain{
public:
static void init_for_state()noexcept;
// 切换不同的 chain
inline static void bind_a_chain( const std::string &chainName_ )noexcept{
tprAssert( ColorNodeChain::chains.find(chainName_) != ColorNodeChain::chains.end() );
ColorNodeChain::currentChainPtr = ColorNodeChain::chains.at(chainName_).get();
//--
ColorNodeChain::nodeIdx = 0;
}
// 自动计算 本帧的 颜色
static const Color &calc_next_baseColor()noexcept{
const ColorNode &node = ColorNodeChain::currentChainPtr->get_node( ColorNodeChain::nodeIdx );
bool ret = ColorNodeChain::currentColor.close_to( *node.colorPtr , node.closePct );
if( !ret ){
ColorNodeChain::nodeIdx++;
if( ColorNodeChain::nodeIdx >= ColorNodeChain::currentChainPtr->nodes.size() ){
ColorNodeChain::nodeIdx = 0;
}
}
//===
return ColorNodeChain::currentColor;
}
private:
// 在构造语句中,直接创建 nodes
explicit ColorNodeChain( std::vector<ColorNode> &&nodes_ ):
nodes( std::move(nodes_) )
{}
const ColorNode &get_node( size_t idx_ )const noexcept{
tprAssert( this->nodes.size() > idx_ );
return this->nodes.at(idx_);
}
const std::vector<ColorNode> nodes; // 在 init 就被创建的 固定不变的数据
//------------ all chains --------------//
static std::unordered_map<std::string, std::unique_ptr<ColorNodeChain>> chains;
//------------- user data -------------//
static const ColorNodeChain *currentChainPtr;
static size_t nodeIdx; // 指向 currentChain 中的 targetNode
static Color currentColor; // 调和色,返回给用户
};
}//------------- namespace gameObjs::bioSoup: end ----------------
#endif
|
turesnake/tprPixelGames | src/Engine/tools/History.h | /*
* ========================= History.h ==========================
* -- tpr --
* CREATE -- 2018.11.24
* MODIFY --
* ----------------------------------------------------------
*/
#ifndef TPR_HISTORY_H
#define TPR_HISTORY_H
// 如果 某个变量 需要暂存旧状态,使用此装置来管理
template< typename T >
class History{
public:
explicit History( const T &val_ ):
oldVal(val_),
newVal(val_),
isDirty(false)
{}
inline void reset( const T &val_ )noexcept{
this->oldVal = val_;
this->newVal = val_;
this->isDirty = false;
}
// 更新 new 值,和 flag
// 若 T 没有 != 运算符,编译阶段会直接报错
inline void set_newVal( const T &newVal_ )noexcept{
if( this->newVal != newVal_ ){
this->newVal = newVal_;
this->isDirty = true;
}
}
inline const T &get_oldVal()const noexcept{ return this->oldVal; }
inline const T &get_newVal()const noexcept{ return this->newVal; }
// 每一渲染帧 起始处调用,检测 上一帧的操作 是否被同步
// 如果未同步,说明流程不干净,外部应该直接报错
inline bool get_isDirty()const noexcept{ return this->isDirty; }
// 同步数据,清空 old 槽
inline void sync()noexcept{
if( this->isDirty ){
this->isDirty = false;
this->oldVal = this->newVal;
}
}
private:
T oldVal; // last
T newVal; // current
bool isDirty;
};
#endif
|
turesnake/tprPixelGames | src/Engine/map/chunkCreateRelease/ChunkCreateReleaseZone.h | <reponame>turesnake/tprPixelGames
/*
* ================= ChunkCreateReleaseZone.h =======================
* -- tpr --
* CREATE -- 2019.07.09
* MODIFY --
* ----------------------------------------------------------
*/
#ifndef TPR_CHUNK_CREATE_ZONE_H
#define TPR_CHUNK_CREATE_ZONE_H
#include "pch.h"
//-------------------- Engine --------------------//
#include "Chunk.h"
#include "NineDirection.h"
// only two instances in esrc:
// -- chunkCreateZone
// -- chunkReleaseZone
class ChunkZone{
public:
explicit ChunkZone( int sideLen_ ): //- based on chunk
sideLen(sideLen_),
offLen(sideLen_/2),
offLenMPos(offLen*ENTS_PER_CHUNK<>),
chunkNums( cast_2_size_t(sideLen_*sideLen_) )
{
tprAssert( (sideLen_>0) && (sideLen_%2 != 0) );
}
inline int get_offLenMPos() const noexcept{ return this->offLenMPos; }
inline int get_offLen() const noexcept{ return this->offLen; }
inline size_t get_chunkNums() const noexcept{ return this->chunkNums; }
private:
//===== vals =====//
int sideLen {}; //- alin to chunks
int offLen {}; //- alin to chunks
int offLenMPos {}; //- 半边长, alin to chunk-mpos
size_t chunkNums {};
};
class ChunkCreateReleaseZone{
public:
ChunkCreateReleaseZone( int sideLen_create_,
int sideLen_release_ ): //- based on chunk
createZone( sideLen_create_),
releaseZone(sideLen_release_),
LimitOff( std::abs(createZone.get_offLenMPos() - releaseZone.get_offLenMPos()) )
{
tprAssert( sideLen_create_ == 3 ); //- tmp
this->init_createZoneOffMPosesSets();
this->init_releaseZoneOffMPoses();
}
void init( IntVec2 playerMPos_ );
inline const std::vector<IntVec2> &get_createZoneOffMPoses( NineDirection dir_ ) const noexcept{
tprAssert( dir_ != NineDirection::Center );
return this->createZoneOffMPosesSets.at(dir_);
}
inline const std::vector<IntVec2> &get_releaseZoneOffMPoses() const noexcept{
return this->releaseZoneOffMPoses;
}
void refresh_and_collect_chunks_need_to_be_release( IntVec2 playerMPos_ ); // major-func
private:
void init_createZoneOffMPosesSets();
void init_releaseZoneOffMPoses();
//===== vals =====//
ChunkZone createZone;
ChunkZone releaseZone;
int LimitOff; //- 释放圈 比 新建圈 大出的 半边长,alin to chunk-mpos
// 当 两圈center间距离,大于此值,说明新建圈越界,要推动 释放圈了
IntVec2 releaseZoneCenterChunkMCPos {};
//-- 轮流扮演 old/new 容器,容纳 释放圈覆盖的所有 chunkkeys --
std::unordered_set<chunkKey_t> releaseChunkKeys_A {};
std::unordered_set<chunkKey_t> releaseChunkKeys_B {};
//- 根据 player 的运动方向,来选择不同的 新建chunks次序。
// 确保优先创建 运动方向前方的 chunks
// key 仅为 player 运动方向
// ---
// 目前版本 固定 3*3 激活圈
std::unordered_map<NineDirection, std::vector<IntVec2>> createZoneOffMPosesSets {};
//- 释放圈 所有 chunk.offMPos
// 尺寸基于 releaseZone.sideLen
std::vector<IntVec2> releaseZoneOffMPoses {};
//===== flags =====//
bool is_currentOld_in_A {};
};
#endif
|
turesnake/tprPixelGames | src/Engine/camera/Camera.h | /*
* ========================= Camera.h ==========================
* -- tpr --
* CREATE -- 2018.11.24
* MODIFY --
* ----------------------------------------------------------
*/
#ifndef TPR_CAMERA_H
#define TPR_CAMERA_H
//=== *** glad FIRST, glfw SECEND *** ===
// Don't include glfw3.h ALONE!!!
#include<glad/glad.h>
#include<GLFW/glfw3.h>
#include "pch.h"
//-------------------- Engine --------------------//
#include "ViewingBox.h"
#include "FloatVec.h"
class Camera{
public:
Camera():
targetDPos(glm::dvec2(0.0, 0.0)),
currentDPos(glm::dvec2(0.0, 0.0)),
renderDPos(glm::dvec3(0.0, 0.0, ViewingBox::halfZ ))
{
this->init();
}
void RenderUpdate();
bool is_in_renderScope( const glm::dvec2 &dpos_ )const noexcept;
glm::mat4 &update_mat4_view();
inline glm::mat4 &update_mat4_projection(){
if( !this->isProjectionSet ){
this->isProjectionSet = true; // only once
}
//-- 在未来,WORK_WIDTH/WORK_HEIGHT 会成为变量(随窗口尺寸而改变)
// 所以不推荐,将 ow/oh 写成定值
float ow = 0.5f * static_cast<float>(ViewingBox::gameSZ.x); //- 横向边界半径(像素)
float oh = 0.5f * static_cast<float>(ViewingBox::gameSZ.y); //- 纵向边界半径(像素)
//------ relative: zNear / zFar --------
// 基于 currentDPos, 沿着 cameraFront 方向,推进 zNear_relative,此为近平面
// 基于 currentDPos, 沿着 cameraFront 方向,推进 zFar_relative, 此为远平面
// 两者都是 定值(无需每帧变化)
float zNear_relative = 0.0f; //- 负数也接受
float zFar_relative = static_cast<float>(ViewingBox::z);
this->mat4_projection = glm::ortho( -ow, //-- 左边界
ow, //-- 右边界
-oh, //-- 下边界
oh, //-- 上边界
zNear_relative, //-- 近平面
zFar_relative ); //-- 远平面
return this->mat4_projection;
}
//-- 瞬移到 某位置 --
// 目前仅用于 sceneWorld 的 perpare 阶段
inline void set_allDPos( const glm::dvec2 &tpos_ )noexcept{
this->currentDPos.x = tpos_.x;
this->currentDPos.y = tpos_.y + 25.0; //- 不是完全对齐,而是留了段小距离来运动
this->targetDPos = tpos_;
this->isMoving = true;
}
//- 外部代码控制 camera运动 的唯一方式
inline void set_targetDPos( const glm::dvec2 &tpos_, double approachPercent_=0.1 )noexcept{
if( tpos_ == this->targetDPos ){
return;
}
this->targetDPos = tpos_;
this->isMoving = true;
this->approachPercent = approachPercent_;
}
inline glm::dvec2 get_currentDPos() const noexcept{
return this->currentDPos;
}
//--- used for render DEEP_Z --
//-- 注意,此处的 zNear/zFar 是相对世界坐标的 绝对值
inline double get_zNear()const noexcept{ return this->renderDPos.z; }
inline double get_zFar()const noexcept{ return (this->renderDPos.z - ViewingBox::z); }
inline bool get_isMoving()const noexcept{ return this->isMoving; }
inline bool get_isProjectionSet()const noexcept{ return this->isProjectionSet; }
//-- only return true in first frame --
inline bool get_isFirstFrame()noexcept{
if( this->isFirstFrame ){
this->isFirstFrame = false;
return true;
}
return false;
}
inline glm::vec2 calc_canvasFPos()const noexcept{
float w = static_cast<float>(this->currentDPos.x) - (0.5f * static_cast<float>(ViewingBox::gameSZ.x));
float h = static_cast<float>(this->currentDPos.y) - (0.5f * static_cast<float>(ViewingBox::gameSZ.y));
return glm::vec2{ w, h };
}
//-- canvas.chunk_fpos [left-bottom]
FloatVec2 calc_canvasCFPos()const noexcept;
private:
void init()noexcept;
//------ 观察/投影 矩阵 -----
glm::mat4 mat4_view = glm::mat4(1.0); //-- 观察矩阵,默认初始化为 单位矩阵
glm::mat4 mat4_projection = glm::mat4(1.0); //-- 投影矩阵,默认初始化为 单位矩阵
//------ 坐标向量 -------
//- in worldCoord -
glm::dvec2 targetDPos;
glm::dvec2 currentDPos;
//- in renderCoord/windowCoord -
glm::dvec3 renderDPos;
double approachPercent {0.1}; //- camera运动的 “接近比率”
//------ 方向向量 -------
//-- 以下3个向量 都是 单位向量
//-- 二维游戏的 摄像机视角是固定的,不需要每帧运算 --
glm::vec3 cameraFront { glm::vec3(0.0f, 0.0f, -1.0f) }; //-- 摄像机 观察的方向
//glm::vec3 cameraRight { glm::vec3(1.0f, 0.0f, 0.0f) }; //-- 摄像机 右手 指向的方向。 未被使用...
glm::vec3 cameraUp { glm::vec3(0.0f, 1.0f, 0.0f) }; //-- 摄像机 头顶向上 指向的方向。
//glm::vec3 worldUp { glm::vec3(0.0f, 1.0f, 0.0f) }; //-- 世界轴的 Up方向,和 cameraUp 有区别。 未被使用...
//===== flags =====//
bool isMoving {true}; //- 是否在移动
bool isFirstFrame {true}; //- 游戏第一帧
bool isProjectionSet {false}; //- 目前游戏中,mat4_projection 只需要被传入gl一次 ...
};
#endif
|
turesnake/tprPixelGames | src/Engine/map/chunkKey.h | /*
* ====================== chunkKey.h =======================
* -- tpr --
* CREATE -- 2019.01.07
* MODIFY --
* ----------------------------------------------------------
* Chunk "id": (int)w + (int)h
* ----------------------------
*/
#ifndef TPR_CHUNK_KEY_H
#define TPR_CHUNK_KEY_H
//--- glm - 0.9.9.5 ---
#include "glm_no_warnings.h"
//-------------------- CPP --------------------//
#include <vector>
//-------------------- Engine --------------------//
#include "tprAssert.h"
#include "config.h"
#include "IntVec.h"
#include "MapCoord.h"
using chunkKey_t = uint64_t;
chunkKey_t chunkMPos_2_key_inn( IntVec2 chunkMPos_ )noexcept; //- 不推荐外部代码使用
IntVec2 chunkKey_2_mpos( chunkKey_t key_ )noexcept;
IntVec2 anyMPos_2_chunkMPos( IntVec2 mpos_ )noexcept;
IntVec2 get_chunk_lMPosOff( IntVec2 anyMPos_ )noexcept;
chunkKey_t anyMPos_2_chunkKey( IntVec2 anyMPos_ )noexcept;
chunkKey_t chunkMPos_2_chunkKey( IntVec2 chunkMPos_ )noexcept;
size_t get_chunkIdx_in_section( IntVec2 anyMPos_ )noexcept;
IntVec2 chunkMPos_2_chunkCPos( IntVec2 chunkMPos_ )noexcept;
/* ===========================================================
* chunkMPos_2_key_inn [内部使用]
* -----------------------------------------------------------
* -- 传入 chunk左下角mpos,获得 chunk key(u64)
*/
inline chunkKey_t chunkMPos_2_key_inn( IntVec2 chunkMPos_ )noexcept{
chunkKey_t key {};
int *ptr = (int*)(&key); //- 此处不能使用 static_casts
*ptr = chunkMPos_.x;
ptr++;
*ptr = chunkMPos_.y;
//--------
return key;
}
/* ===========================================================
* chunkKey_2_mpos
* -----------------------------------------------------------
* -- 传入某个key,生成其 chunk 的 mpos
*/
inline IntVec2 chunkKey_2_mpos( chunkKey_t key_ )noexcept{
IntVec2 mpos {};
int *ptr = (int*)&key_;
//---
mpos.x = *ptr;
ptr++;
mpos.y = *ptr;
//---
return mpos;
}
/* ===========================================================
* anyMPos_2_chunkMPos
* -----------------------------------------------------------
* -- 传入 任意 mapent 的 mpos,获得其 所在 chunk 的 mpos(chunk左下角)
*/
inline IntVec2 anyMPos_2_chunkMPos( IntVec2 anyMPos_ )noexcept{
return ( floorDiv(anyMPos_, ENTS_PER_CHUNK_D) * ENTS_PER_CHUNK<> );
}
/* ===========================================================
* is_a_chunkMPos
* -----------------------------------------------------------
* -- 检测 目标参数, 是否为 chunk mpos (多用于 tprAssert )
*/
inline bool is_a_chunkMPos( IntVec2 anyMPos_ )noexcept{
return ( anyMPos_2_chunkMPos(anyMPos_) == anyMPos_ ); //- 不需要考虑性能
}
/* ===========================================================
* get_chunk_lMPosOff
* -----------------------------------------------------------
* -- 获得 目标mapent.mpos 在其 chunk 中的 相对mpos偏移
*/
inline IntVec2 get_chunk_lMPosOff( IntVec2 anyMPos_ )noexcept{
return ( anyMPos_ - anyMPos_2_chunkMPos(anyMPos_) );
}
/* ===========================================================
* anyMPos_2_chunkKey
* -----------------------------------------------------------
* -- 当需要通过 mpos 计算出它的 key,又不需要 正式制作一个 ChunkKey实例时,
* 推荐使用本函数。
* -- 这个函数会使得调用者代码 隐藏一些bug。
* 在明确自己传入的参数就是 chunkMPos 时,推荐使用 chunkMPos_2_chunkKey()
* param: anyMPos_ -- 任意 mapent 的 mpos
*/
inline chunkKey_t anyMPos_2_chunkKey( IntVec2 anyMPos_ )noexcept{
IntVec2 chunkMPos = anyMPos_2_chunkMPos( anyMPos_ );
return chunkMPos_2_key_inn( chunkMPos );
}
inline chunkKey_t anyDPos_2_chunkKey( const glm::dvec2 &anyDPos_ )noexcept{
IntVec2 chunkMPos = anyMPos_2_chunkMPos( dpos_2_mpos(anyDPos_) ); //-- 未来做优化
return chunkMPos_2_key_inn( chunkMPos );
}
/* ===========================================================
* chunkMPos_2_chunkKey
* -----------------------------------------------------------
* -- 当使用者 确定自己传入的参数就是 chunkMPos, 使用此函数
* 如果参数不为 chunkMPos,直接报错。
*/
inline chunkKey_t chunkMPos_2_chunkKey( IntVec2 chunkMPos_ )noexcept{
tprAssert( anyMPos_2_chunkMPos(chunkMPos_) == chunkMPos_ ); //- tmp
return chunkMPos_2_key_inn( chunkMPos_ );
}
/* ===========================================================
* chunkMPos_2_chunkCPos
* -----------------------------------------------------------
* -- 当使用者 确定自己传入的参数就是 chunkMPos, 使用此函数
* 如果参数不为 chunkMPos,直接报错。
*/
inline IntVec2 chunkMPos_2_chunkCPos( IntVec2 chunkMPos_ )noexcept{
tprAssert( anyMPos_2_chunkMPos(chunkMPos_) == chunkMPos_ ); //- tmp
return floorDiv( chunkMPos_, ENTS_PER_CHUNK_D );
}
#endif
|
turesnake/tprPixelGames | src/Engine/renderPool/RenderPool.h | /*
* ======================= RenderPool.h ==========================
* -- tpr --
* CREATE -- 2019.09.22
* MODIFY --
* ----------------------------------------------------------
*/
#ifndef TPR_RENDER_POOL_H
#define TPR_RENDER_POOL_H
//-------------------- CPP --------------------//
#include <vector>
#include <map>
#include <unordered_set>
//-------------------- Engine --------------------//
#include "ChildMesh.h"
#include "Mesh.h"
enum class RenderPoolType{
Nil,
Opaque, // above biosoup
Translucent, // above biosoup
Shadow // tmp
};
class RenderPool{
public:
explicit RenderPool( bool isOpaque_ ):
isOpaque(isOpaque_)
{}
inline void insert( float zOff_, ChildMesh *meshPtr_ )noexcept{
this->pool.insert({ zOff_, meshPtr_ });// multi
}
inline void clear()noexcept{ this->pool.clear(); }
inline void draw()noexcept{
if( this->isOpaque ){ //- true: 先渲染 pos.z 值大的(近处优先)
for( auto it = this->pool.rbegin();
it != this->pool.rend(); it++ ){
it->second->draw();
}
}else{//- false: 先渲染 pos.z 值小的(远处优先)
for( auto &pair : this->pool ){
pair.second->draw();
}
}
}
inline size_t get_poolSize()const noexcept{ return this->pool.size(); }
private:
std::multimap<float, ChildMesh*> pool {};
bool isOpaque;
//- true: 先渲染 pos.z 值大的(近处优先)
//- false: 先渲染 pos.z 值小的(远处优先)
};
#endif
|
turesnake/tprPixelGames | src/Engine/map/Density.h | /*
* ====================== Density.h =======================
* -- tpr --
* CREATE -- 2019.03.23
* MODIFY --
* ----------------------------------------------------------
* 密度 一个 世界区域划分规则。
* 密度将游戏空间划分为 数段等高线(>=0 为 高地,<0 为低地)
* 只有 field 才需要记录自己的 density 值
* ----------------------------
*/
#ifndef TPR_DENSITY_H
#define TPR_DENSITY_H
//------------------- CPP --------------------//
#include <vector>
//------------------- Engine --------------------//
#include "tprAssert.h"
#include "IntVec.h"
class EcoObj;
//--- [mem] ---
class Density{
public:
Density() = default;
//-- 手动指定 lvl值,仅用于特殊场合 --
explicit Density( int lvl_ ):
lvl(lvl_)
{
tprAssert( (lvl_>=Density::minLvl) && (lvl_<=Density::maxLvl) );
}
Density(IntVec2 fieldMPos_,
double ecoObj_densitySeaLvlOff_,
const std::vector<double> *ecoObj_densityDivideValsPtr_ )
{
this->init( fieldMPos_, ecoObj_densitySeaLvlOff_, ecoObj_densityDivideValsPtr_ );
}
inline constexpr int get_lvl() const noexcept{ return this->lvl; }
//-- 主要用于 遍历一些容器 --
inline size_t get_idx() const noexcept{
switch( this->lvl ){
case -3: return 0;
case -2: return 1;
case -1: return 2;
case 0: return 3;
case 1: return 4;
case 2: return 5;
case 3: return 6;
default:
tprAssert(0);
return 0; //- never reach
}
}
static size_t get_idxNum()noexcept{
return 7; //- 一共7档
}
static int get_minLvl()noexcept{
return Density::minLvl;
}
static int get_maxLvl()noexcept{
return Density::maxLvl;
}
static size_t lvl_2_idx( int lvl_ )noexcept{
switch( lvl_ ){
case -3: return 0;
case -2: return 1;
case -1: return 2;
case 0: return 3;
case 1: return 4;
case 2: return 5;
case 3: return 6;
default:
tprAssert(0);
return 0; //- never reach
}
}
private:
void init( IntVec2 fieldMPos_,
double ecoObj_densitySeaLvlOff_,
const std::vector<double> *ecoObj_densityDivideValsPtr_ );
//===== vals =====//
int lvl {0}; // [-3, 3] 共7档
//===== static =====//
static int minLvl; // -3
static int maxLvl; // 3
};
inline constexpr bool operator < ( Density a_, Density b_ ) noexcept {
return (a_.get_lvl() < b_.get_lvl());
}
inline constexpr bool operator == ( Density a_, Density b_ ) noexcept {
return (a_.get_lvl() == b_.get_lvl());
}
inline constexpr bool operator != ( Density a_, Density b_ ) noexcept {
return (a_.get_lvl() != b_.get_lvl());
}
#endif
|
turesnake/tprPixelGames | src/Engine/tools/tprMath.h | /*
* ======================== tprMath.h ==========================
* -- tpr --
* CREATE -- 2019.08.21
* MODIFY --
* ----------------------------------------------------------
*/
#ifndef TPR_MATH_H
#define TPR_MATH_H
//--- glm - 0.9.9.5 ---
#include "glm_no_warnings.h"
//-------------------- CPP --------------------//
#include <cmath>
//-------------------- Engine --------------------//
#include "tprAssert.h"
#ifndef TPR_PI
#define TPR_PI 3.14159
#endif
#ifndef TPR_2PI
#define TPR_2PI 6.28319
#endif
template< typename T >
inline T tprMin( T a_, T b_ )noexcept{
return ((a_ <= b_) ? a_ : b_);
}
template< typename T >
inline T tprMax( T a_, T b_ )noexcept{
return ((a_ >= b_) ? a_ : b_);
}
//-- just need overload "<" --
template< typename T >
inline bool is_closeEnough( T a_, T b_, T threshold_ )noexcept{
return ((a_ < b_) ? ((b_-a_) < threshold_) :
((a_-b_) < threshold_));
}
inline bool is_closeEnough( const glm::dvec2 &a_, const glm::dvec2 &b_, double step_=0.01 )noexcept{
return ( (std::abs(a_.x - b_.x) <= step_) &&
(std::abs(a_.y - b_.y) <= step_) );
}
/* ===========================================================
* rotate_vec
* -----------------------------------------------------------
* 将向量 beVec_ 沿0点旋转一个角度, 角度就是 rotateVec_ 与 x轴正方向的夹角
* 返回旋转后的 向量
*/
/*
inline glm::dvec2 rotate_vec( const glm::dvec2 &beVec_, const glm::dvec2 &rotateVec_ ) noexcept {
tprAssert( !((rotateVec_.x==0.0) && (rotateVec_.y==0.0)) );
glm::dvec2 n = glm::normalize( rotateVec_ );
const glm::dvec2 &t = beVec_;
//- mutex
return glm::dvec2 { (n.x * t.x) - (n.y * t.y),
(n.y * t.x) + (n.x * t.y) };
}
*/
/* ===========================================================
* calc_innVec
* -----------------------------------------------------------
* 计算 目标向量 beVec_ 在 基向量 baseVec_ 体内的 向量值
* 旋转 基向量,使其躺平到 x轴,对齐与 0 点
* 返回新坐标系中的 目标向量值(向量长度不变)
*/
inline glm::dvec2 calc_innVec( const glm::dvec2 &baseVec_, const glm::dvec2 &beVec_ ) noexcept {
tprAssert( !((baseVec_.x==0.0) && (baseVec_.y==0.0)) );
glm::dvec2 n = glm::normalize( baseVec_ );
const glm::dvec2 &t = beVec_;
//- mutex
return glm::dvec2 { (n.x * t.x) + (n.y * t.y),
-(n.y * t.x) + (n.x * t.y) }; //- 注意,要使用反向角度的 矩阵
}
//- 四舍五入
inline double tprRound( double num_ ){
return (num_>0.0) ?
floor( num_ + 0.5 ) :
ceil( num_ - 0.5 );
}
inline float tprRound( float num_ ){
return (num_>0.0f) ?
floor( num_ + 0.5f ) :
ceil( num_ - 0.5f );
}
inline glm::dvec2 tprRound( const glm::dvec2 &v_ ){
return glm::dvec2{ tprRound(v_.x),
tprRound(v_.y) };
}
// 基于 uWeight,生成一个 (0.0, 1.0) 的小数随机数
inline double calc_uWeight_fractValue( size_t uWeight ){
double rd = static_cast<double>(uWeight) / 3.173;
double integer {}; // 不会被使用
double fract = modf(rd, &integer); // (0.0, 0.1)
return fract;
}
#endif
|
turesnake/tprPixelGames | src/Engine/resource/esrc_all.h | /*
* ========================= esrc_all.h ==========================
* -- tpr --
* CREATE -- 2019.04.19
* MODIFY --
* ----------------------------------------------------------
* 全部 esrc_xxx.h 文件
* 目前仅用于 main.cpp 文件
* ----------------------------
*/
#ifndef TPR_ESRC_ALL_H
#define TPR_ESRC_ALL_H
//-------------------- Engine --------------------//
#include "esrc_animFrameSet.h"
#include "esrc_behaviour.h"
#include "esrc_camera.h"
#include "esrc_canvas.h"
#include "esrc_chunk.h"
#include "esrc_coordinate.h"
#include "esrc_job_chunk.h"
#include "esrc_job_ecoObj.h"
#include "esrc_colorTableSet.h"
#include "esrc_ecoSysPlan.h"
#include "esrc_ecoObj.h"
#include "esrc_ecoObjMemState.h"
#include "esrc_field.h"
#include "esrc_gameArchive.h"
#include "esrc_gameObj.h"
#include "esrc_gameSeed.h"
#include "esrc_jobQue.h"
#include "esrc_player.h"
#include "esrc_renderPool.h"
#include "esrc_shader.h"
#include "esrc_thread.h"
#include "esrc_time.h"
#include "esrc_uniformBlockObj.h"
#include "esrc_VAOVBO.h"
#include "esrc_window.h"
#endif
|
turesnake/tprPixelGames | src/Engine/sys/prepare.h | <filename>src/Engine/sys/prepare.h
/*
* ========================= prepare.h ==========================
* -- tpr --
* CREATE -- 2019.05.23
* MODIFY --
* ----------------------------------------------------------
* main 函数 的前期 准备工作
* ----------------------------
*/
#ifndef TPR_PREPARE_H
#define TPR_PREPARE_H
void prepare( char *exeDirPath_ );
#endif
|
turesnake/tprPixelGames | src/Engine/color/colorTableId.h | /*
* ======================= colorTableId.h ==========================
* -- tpr --
* CREATE -- 2019.09.023
* MODIFY --
* ----------------------------------------------------------
*/
#ifndef TPR_COLOR_TABLE_ID_H
#define TPR_COLOR_TABLE_ID_H
//------------------- CPP --------------------//
#include <cstdint> // uint8_t
#include <string>
using colorTableId_t = uint32_t;
// 暂不适合用 hash 来生成id
// 此id 肩负 vector idx 的职责
extern const colorTableId_t NilColorTableId;
//-- never reach
#endif
|
turesnake/tprPixelGames | src/Engine/random/PerlinNoise1D.h | /*
* ========================= PerlinNoise1D.h ==========================
* -- tpr --
* CREATE -- 2018.12.03
* MODIFY --
* ----------------------------------------------------------
* Perlin Noise 2D 简易版
* Perlin Noise Next
* ----------------------------
*/
#ifndef TPR_PERLIN_NOISE_1D_H
#define TPR_PERLIN_NOISE_1D_H
#include "random.h"
//--- glm - 0.9.9.5 ---
#include "glm_no_warnings.h"
//------------------- CPP --------------------//
#include <cstdint> // uint8_t
//------------------- Engine --------------------//
#include "tprAssert.h"
//-- 一个 二维版的 perlin noise 曲线 --
// 用法:
// PerlinNoise1D perlin { freq_, ampl_ };
// perlin.init( seed_ );
// int y = perlin.get_y( x_ ); //- 通过x获得对应的y值。
class PerlinNoise1D{
public:
PerlinNoise1D( float freq_ = 1.0f,
float ampl_ = 1.0f ):
freq(freq_),
ampl(ampl_),
isInit( false )
{}
inline void init()noexcept{ //- use auto seed
seed = get_new_seed();
isInit = true;
}
inline void init( uint32_t seed_ )noexcept{ //- use param seed
seed = seed_;
isInit = true;
}
//-- 主功能,传入 perlin曲线的 x值,获得对应的 y值 --
inline float get_y( float x_ )noexcept{
tprAssert( isInit == true );//- 确保 调用者执行 init 函数
x_ *= freq;
float i = glm::floor( x_ ); //- 取 x_ 的整数部分
float f = glm::fract( x_ ); //- 取 x_ 的小数部分
float u = f * f * ( 3.0 - 2.0 * f ); //- 三次多项式 取代 glm::smoothstep()
float y = glm::mix( pseudo_rand( i ),
pseudo_rand( i + 1 ),
u );
y *= ampl;
//------
return y;
}
//-- 手动 更新 seed --
inline void set_seed( uint32_t seed_ )noexcept{
seed = seed_;
}
//-- 自动分配 新seed 值 --
inline void set_seed_auto()noexcept{
seed = get_new_seed();
}
//-- 手动更新 频率 和 振幅 --
inline void set_freq( float freq_ )noexcept{
freq = freq_;
}
//-- 手动更新 频率 和 振幅 --
inline void set_ampl( float ampl_ )noexcept{
ampl = ampl_;
}
private:
//-- 一个恒定不变的 伪随机数 序列 --
//- 通过不同的 整形x
//- 访问这个 序列上的 不同 y值 [ 0.0f, 1.0f ]
inline float pseudo_rand( int intX_ )noexcept{
engine.seed( seed );
engine.discard( intX_ ); //- 前进n个状态
return di(engine);
}
//======== vals ========//
uint32_t seed {}; //- 一个 perlin 实例, 需要一个稳定不变的种子。
std::default_random_engine engine; //- 随机数引擎,默认初始状态
std::uniform_real_distribution<float> di { 0.0f, 1.0f }; //- 分布器
float freq {}; //- 频率
float ampl {}; //- 振幅
bool isInit {}; //- 检查 是否执行 init
};
//-- 针对 perlin noise 曲线 的一种 "特殊但常用" 的方法 --
// 本class 将 perlin 的访问自动化
// 本class 自己维护一个 时快时慢的 x,
// 并自动将 下一个位置的 x 对应的 y 返回给调用者。
class PerlinNoise1DNext{
public:
PerlinNoise1DNext( float freq_,
float ampl_ )
{
pn_main.set_freq( freq_ );
pn_main.set_ampl( ampl_ );
}
inline void init()noexcept{
pn_step.init();
pn_main.init();
}
//-- 主功能 --
// 按照一个 时快时慢的速度访问 perlin 曲线上的值
// 进而获得一个 更加随机的 曲线 y值
inline float next()noexcept{
xstep += 1.0f;
x += pn_step.get_y( xstep );
return pn_main.get_y( x );
}
private:
PerlinNoise1D pn_step { 0.03f, 1.0f };
PerlinNoise1D pn_main {}; //- 主perlin
float x {0.0f}; //- 遍历 pn_main 的光标。
float xstep {0.0f}; //- 遍历 pn_step 的光标
};
#endif
|
turesnake/tprPixelGames | src/Engine/animFrameSet/load_and_divide_png.h | <filename>src/Engine/animFrameSet/load_and_divide_png.h<gh_stars>100-1000
/*
* =================== load_and_divide_png.h =================
* -- tpr --
* CREATE -- 2019.05.06
* MODIFY --
* ----------------------------------------------------------
*/
#ifndef TPR_LOAD_AND_DIVIDE_PNG_H
#define TPR_LOAD_AND_DIVIDE_PNG_H
#include "pch.h"
//------------------- Engine --------------------//
#include "RGBA.h"
IntVec2 load_and_divide_png(const std::string &path_,
IntVec2 frameNum_,
size_t totalFrameNum_,
std::vector< std::vector<RGBA>> &frame_data_ary_ );
#endif
|
turesnake/tprPixelGames | src/Engine/tools/NineDirection.h | <filename>src/Engine/tools/NineDirection.h
/*
* ===================== NineDirection.h ==========================
* -- tpr --
* CREATE -- 2018.12.26
* MODIFY --
* ----------------------------------------------------------
*/
#ifndef TPR_NINE_DIRECTION_H
#define TPR_NINE_DIRECTION_H
//--- glm - 0.9.9.5 ---
#include "glm_no_warnings.h"
//-------------------- CPP --------------------//
#include <string>
//-------------------- Engine --------------------//
#include "tprAssert.h"
#include "tprCast.h"
#include "IntVec.h"
enum class NineDirection{
Center = 0, //- same as No_Direction
Left = 1,
LeftTop = 2,
Top = 3,
RightTop = 4,
Right = 5,
RightBottom = 6,
Bottom = 7,
LeftBottom = 8
};
extern size_t nineDirectionSize;
inline NineDirection intVec2_2_nineDirection( IntVec2 v_ ) noexcept {
if( v_.y < 0 ){
if( v_.x<0 ){ return NineDirection::LeftBottom;
}else if( v_.x==0 ){ return NineDirection::Bottom;
}else{ return NineDirection::RightBottom;
}
}else if( v_.y == 0 ){
if( v_.x<0 ){ return NineDirection::Left;
}else if( v_.x==0 ){ return NineDirection::Center;
}else{ return NineDirection::Right;
}
}else{
if( v_.x<0 ){ return NineDirection::LeftTop;
}else if( v_.x==0 ){ return NineDirection::Top;
}else{ return NineDirection::RightTop;
}
}
}
inline NineDirection dpos_2_nineDirection( const glm::dvec2 &v_ ) noexcept {
if( v_.y < 0.0 ){
if( v_.x<0.0 ){ return NineDirection::LeftBottom;
}else if( v_.x==0.0 ){ return NineDirection::Bottom;
}else{ return NineDirection::RightBottom;
}
}else if( v_.y == 0.0 ){
if( v_.x<0.0 ){ return NineDirection::Left;
}else if( v_.x==0.0 ){ return NineDirection::Center;
}else{ return NineDirection::Right;
}
}else{
if( v_.x<0.0 ){ return NineDirection::LeftTop;
}else if( v_.x==0.0 ){ return NineDirection::Top;
}else{ return NineDirection::RightTop;
}
}
}
inline NineDirection idx_2_nineDirection( size_t idx_ )noexcept{
switch (idx_){
case 0: return NineDirection::Center;
case 1: return NineDirection::Left;
case 2: return NineDirection::LeftTop;
case 3: return NineDirection::Top;
case 4: return NineDirection::RightTop;
case 5: return NineDirection::Right;
case 6: return NineDirection::RightBottom;
case 7: return NineDirection::Bottom;
case 8: return NineDirection::LeftBottom;
default:
tprAssert(0);
return NineDirection::Center; // never reach
}
}
//-- 不包含 Center --
// param: randUVal_ [0, 9999]
inline NineDirection apply_a_random_direction_without_mid( size_t randUVal_ )noexcept{
size_t idx = (randUVal_ + 590179) % (nineDirectionSize-1);
idx++; // 不含 0
return idx_2_nineDirection(idx);
}
//---- only used for debug ----//
std::string nineDirection_2_str( NineDirection dir_ )noexcept;
NineDirection str_2_nineDirection( const std::string &str_ )noexcept;
inline IntVec2 nineDirection_2_mposOff( NineDirection dir_ )noexcept{
switch (dir_){
case NineDirection::Center: return IntVec2{ 0, 0 };
case NineDirection::Left: return IntVec2{ -1, 0 };
case NineDirection::LeftTop: return IntVec2{ -1, 1 };
case NineDirection::Top: return IntVec2{ 0, 1 };
case NineDirection::RightTop: return IntVec2{ 1, 1 };
case NineDirection::Right: return IntVec2{ 1, 0 };
case NineDirection::RightBottom: return IntVec2{ 1, -1 };
case NineDirection::Bottom: return IntVec2{ 0, -1 };
case NineDirection::LeftBottom: return IntVec2{ -1, -1 };
default:
tprAssert(0);
return IntVec2{}; // never reach
}
}
//-返回的 dvec2 仅仅表达一个 方向,并不是 单位向量
inline glm::dvec2 nineDirection_2_dVec2( NineDirection dir_ )noexcept{
switch (dir_){
case NineDirection::Center: return glm::dvec2{ 0.0, 0.0 };
case NineDirection::Left: return glm::dvec2{ -1.0, 0.0 };
case NineDirection::LeftTop: return glm::dvec2{ -1.0, 1.0 };
case NineDirection::Top: return glm::dvec2{ 0.0, 1.0 };
case NineDirection::RightTop: return glm::dvec2{ 1.0, 1.0 };
case NineDirection::Right: return glm::dvec2{ 1.0, 0.0 };
case NineDirection::RightBottom: return glm::dvec2{ 1.0, -1.0 };
case NineDirection::Bottom: return glm::dvec2{ 0.0, -1.0 };
case NineDirection::LeftBottom: return glm::dvec2{ -1.0, -1.0 };
default:
tprAssert(0);
return glm::dvec2{ 0.0, 0.0 }; // never reach
}
}
//- 是否为 斜向 方向
inline bool is_diagonalDir( NineDirection dir_ )noexcept{
switch (dir_){
case NineDirection::LeftTop:
case NineDirection::RightTop:
case NineDirection::RightBottom:
case NineDirection::LeftBottom:
return true;
case NineDirection::Center:
case NineDirection::Left:
case NineDirection::Right:
case NineDirection::Top:
case NineDirection::Bottom:
return false;
default:
tprAssert(0);
return false; // never reach
}
}
#endif
|
turesnake/tprPixelGames | src/Engine/shaderProgram/ShaderType.h | /*
* ========================= ShaderType.h ==========================
* -- tpr --
* CREATE -- 2019.09.23
* MODIFY --
* ----------------------------------------------------------
*/
#ifndef TPR_SHADER_TYPE_H
#define TPR_SHADER_TYPE_H
#include <string>
enum class ShaderType{
Shadow,
//---
Ground,
BioSoupBase,
BioSoupParticle,
//---
OriginColor,
UnifiedColor,
GroundColor,
//---
PlayerGoCircle,
//-- gos --
};
std::string shaderType_2_str( ShaderType type_ )noexcept;
ShaderType str_2_shaderType( const std::string &str_ )noexcept;
#endif
|
turesnake/tprPixelGames | src/Engine/UI/UIAnchor.h | /*
* ======================= UIAnchor.h ========================
* -- tpr --
* 创建 -- 2019.08.28
* 修改 --
* ----------------------------------------------------------
* based on ViewingBox::gameSZ
* a point used in UI sys
* ---------
*/
#ifndef TPR_UI_ANCHOR_H
#define TPR_UI_ANCHOR_H
//--- glm - 0.9.9.5 ---
#include "glm_no_warnings.h"
//-------------------- Engine --------------------//
#include "ViewingBox.h"
#include "tprAssert.h"
class UIAnchor{
public:
//- often used in GameObj class. init() will be delay
UIAnchor() = default;
//- often used to create a single instance.
UIAnchor( const glm::dvec2 &basePointProportion_, // [-1.0,1.0]
const glm::dvec2 &offDPos_ ):
basePointProportion(basePointProportion_),
offDPos(offDPos_)
{
this->check_basePointProportion( basePointProportion_ );
this->init( basePointProportion_, offDPos_ );
}
//--- 基于一个 基点,做一个偏移,计算出 本点的 currentDPos
//- param_1: window 上的 比例点[-1.0,1.0],此为偏移 基点
//- param_2: 绝对偏移值,可写零
void init( const glm::dvec2 &basePointProportion_, // [-1.0,1.0]
const glm::dvec2 &offDPos_ )noexcept{
this->check_basePointProportion( basePointProportion_ );
glm::dvec2 basePointDPos {
static_cast<double>(ViewingBox::gameSZ.x) * 0.5 * basePointProportion_.x,
static_cast<double>(ViewingBox::gameSZ.y) * 0.5 * basePointProportion_.y };
this->currentDPos = basePointDPos + offDPos_;
}
//----- set -----//
inline void set_alti( double alti_ )noexcept{
this->alti = alti_;
}
inline void accum_dpos( const glm::dvec2 &addDPos_ )noexcept{
this->currentDPos += addDPos_;
}
//----- get -----//
inline const glm::dvec2 &get_dpos() const noexcept{ return this->currentDPos; }
inline double get_alti()const noexcept{ return this->alti; }
inline const glm::dvec2 &get_basePointProportion() const noexcept{ return this->basePointProportion; }
inline const glm::dvec2 &get_offDPos() const noexcept{ return this->offDPos; }
private:
inline void check_basePointProportion( const glm::dvec2 &basePointProportion_ )noexcept{
tprAssert( (basePointProportion_.x>=-1.0) && (basePointProportion_.x<=1.0) &&
(basePointProportion_.y>=-1.0) && (basePointProportion_.y<=1.0) );
}
//---- vals -----//
glm::dvec2 currentDPos {}; //- base on window_center.
double alti {}; //- 腾空高度。
//--
glm::dvec2 basePointProportion {};
// 将 window 看成一张 [-1.0,1.0] 的坐标图
// 想要定位一个 uigo,就要先确定一个 basePoint (基于以上坐标系的一个值)
// 最常用的有 中心点,四角点 和 四边中点
glm::dvec2 offDPos {};
// 在 basePointProportion 基础上,
// 再累加一个 像素偏移值
// 以此获得,最终的 uigo 坐标值
};
#endif
|
turesnake/tprPixelGames | src/Engine/actionSwitch/ActionSwitchType.h | /*
* ========================= ActionSwitchType.h ==========================
* -- tpr --
* CREATE -- 2019.02.01
* MODIFY --
* ----------------------------------------------------------
* 这个文件 应该放到 script 层
* ----------------------------
*/
#ifndef TPR_ACTION_SWITCH_TYPE_H
#define TPR_ACTION_SWITCH_TYPE_H
//------------------- CPP --------------------//
#include <cstdint> // uint8_t
//-- 如果 元素数量超过 64个,就需要修改 相关内容
// 千万不能 自定义 元素的值。应该让元素的值按照持续,被自动分配(从0开始增长)
// 元素值将被转换为 idx,用来访问 bitMap
enum class ActionSwitchType : uint32_t{
//--- move ----//
Idle=0, //- 移动中途 停留 时的动画(树木的待机也算)
Move=1, //- 泛指移动,其实有很多种类: walk, run, fly
// 留给 具象go类 自己去分配
//BeCollide_From_Left, //- 受到来自左侧的碰撞后,播放的动画
//BeCollide_From_Right, //- 受到来自右侧的碰撞后,播放的动画
//...
Burn, // fire
selfRotate, //- 仅被 PlayerGoCircle 使用 tmp
ButtonState_1, //- tmp
ButtonState_2, //- tmp
};
#endif
|
turesnake/tprPixelGames | src/Engine/resource/esrc_ecoObjMemState.h | <filename>src/Engine/resource/esrc_ecoObjMemState.h
/*
* ================== esrc_ecoObjMemState.h ==========================
* -- tpr --
* CREATE -- 2019.11.29
* MODIFY --
* ----------------------------------------------------------
* only included by esrc_ecoObj.h
*/
#ifndef TPR_ESRC_ECO_OBJ_MEM_STATE_H
#define TPR_ESRC_ECO_OBJ_MEM_STATE_H
//-------------------- CPP --------------------//
#include <utility>
//-------------------- Engine --------------------//
#include "sectionKey.h"
#include "IntVec.h"
#include "EcoObjMemState.h"
namespace esrc {//------------------ namespace: esrc -------------------------//
void init_ecoObjMemStates()noexcept;
EcoObjMemState get_ecoObjMemState( sectionKey_t ecoObjKey_ )noexcept;
void insert_ecoObjKey_2_onCreating( sectionKey_t ecoObjKey_ )noexcept;
void move_ecoObjKey_from_onCreating_2_active( sectionKey_t ecoObjKey_ )noexcept;
void move_ecoObjKey_from_active_2_onReleasing( sectionKey_t ecoObjKey_ )noexcept;
void erase_ecoObjKey_from_onReleasing( sectionKey_t ecoObjKey_ )noexcept;
}//---------------------- namespace: esrc -------------------------//
#endif
|
turesnake/tprPixelGames | src/Engine/move/SpeedLevel.h | <reponame>turesnake/tprPixelGames<gh_stars>100-1000
/*
* ========================= SpeedLevel.h ==========================
* -- tpr --
* CREATE -- 2019.01.13
* MODIFY --
* ----------------------------------------------------------
* only for GameObj::move
* ----------------------------
*/
#ifndef TPR_SPEED_LEVEL_H
#define TPR_SPEED_LEVEL_H
//--- glm - 0.9.9.5 ---
#include "glm_no_warnings.h"
//------------------- CPP --------------------//
#include <vector>
//------------------- Engine --------------------//
#include "tprAssert.h"
#include "config.h"
//-- 18 level --
enum class SpeedLevel : int {
LV_0 = 0, //- no speed
LV_1, //- low
LV_2,
LV_3,
LV_4,
LV_5,
LV_6,
LV_7,
LV_8,
LV_9,
LV_10,
LV_11,
LV_12,
LV_13,
LV_14,
LV_15,
LV_16,
LV_17,
LV_18,
LV_19 //- highest speed for crawl mode,can't faster than 1mapEnt/1frame
};
inline size_t speedLevel_2_size_t( SpeedLevel lvl_ )noexcept{
return static_cast<size_t>(lvl_);
}
//-- 60HZ 时,一帧的 fpos 速度
extern const std::vector<double> speedTable;
inline SpeedLevel int_2_SpeedLevel( int num_ )noexcept{
switch(num_){
case 0: return SpeedLevel::LV_0;
case 1: return SpeedLevel::LV_1;
case 2: return SpeedLevel::LV_2;
case 3: return SpeedLevel::LV_3;
case 4: return SpeedLevel::LV_4;
case 5: return SpeedLevel::LV_5;
case 6: return SpeedLevel::LV_6;
case 7: return SpeedLevel::LV_7;
case 8: return SpeedLevel::LV_8;
case 9: return SpeedLevel::LV_9;
case 10: return SpeedLevel::LV_10;
case 11: return SpeedLevel::LV_11;
case 12: return SpeedLevel::LV_12;
case 13: return SpeedLevel::LV_13;
case 14: return SpeedLevel::LV_14;
case 15: return SpeedLevel::LV_15;
case 16: return SpeedLevel::LV_16;
case 17: return SpeedLevel::LV_17;
case 18: return SpeedLevel::LV_18;
case 19: return SpeedLevel::LV_19;
default:
tprAssert(0);
return SpeedLevel::LV_0; //- never reach
}
}
inline double SpeedLevel_2_val( SpeedLevel lvl_ )noexcept{
return speedTable.at( speedLevel_2_size_t(lvl_) );
}
inline SpeedLevel calc_higher_speedLvl( SpeedLevel lvl_ )noexcept{
switch (lvl_){
case SpeedLevel::LV_0: return SpeedLevel::LV_1;
case SpeedLevel::LV_1: return SpeedLevel::LV_2;
case SpeedLevel::LV_2: return SpeedLevel::LV_3;
case SpeedLevel::LV_3: return SpeedLevel::LV_4;
case SpeedLevel::LV_4: return SpeedLevel::LV_5;
case SpeedLevel::LV_5: return SpeedLevel::LV_6;
case SpeedLevel::LV_6: return SpeedLevel::LV_7;
case SpeedLevel::LV_7: return SpeedLevel::LV_8;
case SpeedLevel::LV_8: return SpeedLevel::LV_9;
case SpeedLevel::LV_9: return SpeedLevel::LV_10;
case SpeedLevel::LV_10: return SpeedLevel::LV_11;
case SpeedLevel::LV_11: return SpeedLevel::LV_12;
case SpeedLevel::LV_12: return SpeedLevel::LV_13;
case SpeedLevel::LV_13: return SpeedLevel::LV_14;
case SpeedLevel::LV_14: return SpeedLevel::LV_15;
case SpeedLevel::LV_15: return SpeedLevel::LV_16;
case SpeedLevel::LV_16: return SpeedLevel::LV_17;
case SpeedLevel::LV_17: return SpeedLevel::LV_18;
case SpeedLevel::LV_18: return SpeedLevel::LV_19;
case SpeedLevel::LV_19: return SpeedLevel::LV_19; // no change
default:
tprAssert(0);
return SpeedLevel::LV_0; //- never reach
}
}
inline SpeedLevel calc_lower_speedLvl( SpeedLevel lvl_ )noexcept{
switch (lvl_){
case SpeedLevel::LV_0: return SpeedLevel::LV_0; // no change
case SpeedLevel::LV_1: return SpeedLevel::LV_0;
case SpeedLevel::LV_2: return SpeedLevel::LV_1;
case SpeedLevel::LV_3: return SpeedLevel::LV_2;
case SpeedLevel::LV_4: return SpeedLevel::LV_3;
case SpeedLevel::LV_5: return SpeedLevel::LV_4;
case SpeedLevel::LV_6: return SpeedLevel::LV_5;
case SpeedLevel::LV_7: return SpeedLevel::LV_6;
case SpeedLevel::LV_8: return SpeedLevel::LV_7;
case SpeedLevel::LV_9: return SpeedLevel::LV_8;
case SpeedLevel::LV_10: return SpeedLevel::LV_9;
case SpeedLevel::LV_11: return SpeedLevel::LV_10;
case SpeedLevel::LV_12: return SpeedLevel::LV_11;
case SpeedLevel::LV_13: return SpeedLevel::LV_12;
case SpeedLevel::LV_14: return SpeedLevel::LV_13;
case SpeedLevel::LV_15: return SpeedLevel::LV_14;
case SpeedLevel::LV_16: return SpeedLevel::LV_15;
case SpeedLevel::LV_17: return SpeedLevel::LV_16;
case SpeedLevel::LV_18: return SpeedLevel::LV_17;
case SpeedLevel::LV_19: return SpeedLevel::LV_18;
default:
tprAssert(0);
return SpeedLevel::LV_0; //- never reach
}
}
inline glm::dvec2 limit_moveSpeed( const glm::dvec2 &speedV_ )noexcept{
// Avoid Radical Sign / 避免开根号 --
double moveLen = speedV_.x*speedV_.x + speedV_.y*speedV_.y;
if( moveLen < PIXES_PER_MAPENT_D * PIXES_PER_MAPENT_D ){
return speedV_;
}
//-- max legal speed vec --
return glm::normalize(speedV_) * SpeedLevel_2_val(SpeedLevel::LV_19);
}
#endif
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.