repo_name
stringlengths
6
97
path
stringlengths
3
341
text
stringlengths
8
1.02M
turesnake/tprPixelGames
src/Engine/resource/esrc_gameArchive.h
<gh_stars>100-1000 /* * ===================== esrc_gameArchive.h ==================== * -- tpr -- * CREATE -- 2019.05.02 * MODIFY -- * ---------------------------------------------------------- */ #ifndef TPR_ESRC_GAME_ARCHIVE_H #define TPR_ESRC_GAME_ARCHIVE_H //-------------------- Engine --------------------// #include "GameArchive.h" namespace esrc {//------------------ namespace: esrc -------------------------// void init_gameArchive(); GameArchive &get_gameArchive(); }//---------------------- namespace: esrc -------------------------// #endif
turesnake/tprPixelGames
src/Engine/resource/esrc_canvas.h
/* * ========================= esrc_canvas.h ========================== * -- tpr -- * CREATE -- 2019.04.19 * MODIFY -- * ---------------------------------------------------------- */ #ifndef TPR_ESRC_CANVAS_H #define TPR_ESRC_CANVAS_H //-------------------- Engine --------------------// #include "Canvas.h" namespace esrc {//------------------ namespace: esrc -------------------------// void init_canvases(); void draw_groundCanvas(); }//---------------------- namespace: esrc -------------------------// #endif
turesnake/tprPixelGames
src/Engine/multiThread/chunkCreate/Job_GroundGoEnt.h
/* * ====================== Job_GroundGoEnt.h ======================= * -- tpr -- * CREATE -- 2019.09.28 * MODIFY -- * ---------------------------------------------------------- */ #ifndef TPR_JOB_GROUND_GO_ENT_H #define TPR_JOB_GROUND_GO_ENT_H //--- glm - 0.9.9.5 --- #include "glm_no_warnings.h" //-------------------- Engine --------------------// #include "sectionKey.h" #include "colorTableId.h" #include "fieldFractType.h" //-- 每个实例,都会变成 GroundGo 的一个 mesh class Job_GroundGoEnt{ public: Job_GroundGoEnt(FieldFractType type_, const glm::dvec2 dposOff_, colorTableId_t id_, size_t uWeight_ ): fieldFractType(type_), dposOff(dposOff_), colorTableId(id_), uWeight(uWeight_) {} //---------- vals ----------// FieldFractType fieldFractType; glm::dvec2 dposOff; // base on field-midDPos colorTableId_t colorTableId; // 不再需要这个值 size_t uWeight; //[0.0, 9999] }; #endif
turesnake/tprPixelGames
src/Script/gameObjs/bioSoup/BioSoupBase.h
<filename>src/Script/gameObjs/bioSoup/BioSoupBase.h /* * ======================= BioSoupBase.h ========================== * -- tpr -- * CREATE -- 2020.03.06 * MODIFY -- * ---------------------------------------------------------- */ #ifndef TPR_GO_BIO_SOUP_BASE_H #define TPR_GO_BIO_SOUP_BASE_H //--- glm - 0.9.9.5 --- #include "glm_no_warnings.h" //-------------------- CPP --------------------// #include <cmath> #include <vector> #include <map> //-------------------- Engine --------------------// #include "tprAssert.h" #include "animSubspeciesId.h" #include "fieldFractType.h" #include "MapAltitude.h" #include "SignInMapEnts_Square_Type.h" //-------------------- Script --------------------// #include "Script/gameObjs/bioSoup/BioSoupState.h" namespace gameObjs::bioSoup {//------------- namespace gameObjs::bioSoup ---------------- class BioSoupBase{ public: BioSoupBase() { if( !BioSoupBase::isStaticInit ){ BioSoupBase::isStaticInit = true; BioSoupBase::init_for_static(); } } inline void init( size_t uWeight_, State bioSoupState_, SignInMapEnts_Square_Type squType_ )noexcept{ this->uWeight = uWeight_; this->bioSoupState = bioSoupState_; // fieldFractType // animSubspeciesId size_t idx {}; switch( squType_ ){ case SignInMapEnts_Square_Type::T_1m1: this->fieldFractType = FieldFractType::MapEnt; idx = (uWeight_ + 69761733) % BioSoupBase::animSubspeciesIdSets_1m1.size(); this->animSubspeciesIdsPtr = &BioSoupBase::animSubspeciesIdSets_1m1.at(idx); break; case SignInMapEnts_Square_Type::T_2m2: this->fieldFractType = FieldFractType::HalfField; idx = (uWeight_ + 69761733) % BioSoupBase::animSubspeciesIdSets_2m2.size(); this->animSubspeciesIdsPtr = &BioSoupBase::animSubspeciesIdSets_2m2.at(idx); break; case SignInMapEnts_Square_Type::T_4m4: this->fieldFractType = FieldFractType::Field; idx = (uWeight_ + 69761733) % BioSoupBase::animSubspeciesIdSets_4m4.size(); this->animSubspeciesIdsPtr = &BioSoupBase::animSubspeciesIdSets_4m4.at(idx); break; default: tprAssert(0); } } inline animSubspeciesId_t get_next_animSubspeciesId()noexcept{ this->animSubspeciesIdCount++; if( this->animSubspeciesIdCount >= this->animSubspeciesIdsPtr->size() ){ this->animSubspeciesIdCount = 0; } return this->animSubspeciesIdsPtr->at(this->animSubspeciesIdCount); } private: static void init_for_static(); size_t uWeight {}; State bioSoupState {}; // 暂时无用 FieldFractType fieldFractType {}; std::vector<animSubspeciesId_t> *animSubspeciesIdsPtr {nullptr}; size_t animSubspeciesIdCount {0}; //======= static =======// static bool isStaticInit; static std::vector<std::vector<animSubspeciesId_t>> animSubspeciesIdSets_1m1; static std::vector<std::vector<animSubspeciesId_t>> animSubspeciesIdSets_2m2; static std::vector<std::vector<animSubspeciesId_t>> animSubspeciesIdSets_4m4; }; }//------------- namespace gameObjs::bioSoup: end ---------------- #endif
turesnake/tprPixelGames
src/Engine/map/chunkCreateRelease/chunkRelease.h
<reponame>turesnake/tprPixelGames<gh_stars>100-1000 /* * =================== chunkRelease.h ======================= * -- tpr -- * CREATE -- 2019.07.11 * MODIFY -- * ---------------------------------------------------------- */ #ifndef TPR_CHUNK_RELEASE_H #define TPR_CHUNK_RELEASE_H //-------------------- Engine --------------------// #include "IntVec.h" #include "fieldKey.h" #include "chunkKey.h" namespace chunkRelease {//------- namespace: chunkRelease ----------// void collect_chunks_need_to_be_release_in_update(); void release_one_chunk(); }//----------------- namespace: chunkRelease: end -------------------// #endif
turesnake/tprPixelGames
src/Engine/resource/esrc_chunk.h
<gh_stars>100-1000 /* * ========================= esrc_chunk.h ========================== * -- tpr -- * CREATE -- 2019.04.19 * MODIFY -- * ---------------------------------------------------------- */ #ifndef TPR_ESRC_CHUNK_H #define TPR_ESRC_CHUNK_H //-------------------- CPP --------------------// #include <string> #include <utility> //-------------------- Engine --------------------// #include "Chunk.h" #include "chunkKey.h" #include "IntVec.h" #include "ChunkCreateReleaseZone.h" #include "ChunkMemState.h" #include "esrc_chunkMemState.h" namespace esrc {//------------------ namespace: esrc -------------------------// void init_chunks(); void init_chunkCreateReleaseZone( IntVec2 playerMPos_ ); ChunkCreateReleaseZone &get_chunkCreateReleaseZoneRef(); void chunks_debug(); Chunk &insert_and_init_new_chunk( chunkKey_t chunkKey_ ); void erase_from_chunks( chunkKey_t chunkKey_ ); std::pair<ChunkMemState, MemMapEnt*> getnc_memMapEntPtr( IntVec2 anyMPos_ ); std::pair<ChunkMemState, Chunk*> get_chunkPtr( chunkKey_t key_ ); Chunk &get_chunkRef_onReleasing( chunkKey_t key_ ); }//---------------------- namespace: esrc -------------------------// #endif
turesnake/tprPixelGames
src/Engine/multiThread/JobType.h
/* * ========================== JobType.h ======================= * -- tpr -- * CREATE -- 2019.04.24 * MODIFY -- * ---------------------------------------------------------- */ #ifndef TPR_JOB_TYPE_H #define TPR_JOB_TYPE_H enum class JobType : int{ Null = 0, JustTimeOut = 1, //- 不是 job 类型,而是告诉 job线程: // “本次返回仅仅是因为 时间到了,请再次尝试 提取job” Create_Job_Chunk, Create_Job_EcoObj, }; #endif
turesnake/tprPixelGames
src/Engine/blueprint/blueprint.h
/* * ======================= blueprint.h ======================= * -- tpr -- * CREATE -- 2019.12.04 * MODIFY -- * ---------------------------------------------------------- * interface */ #ifndef TPR_BLUE_PRINT_H #define TPR_BLUE_PRINT_H #include "pch.h" //-------------------- Engine --------------------// #include "blueprintId.h" #include "mapEntKey.h" #include "GoDataForCreate.h" #include "fieldKey.h" namespace blueprint {//------------------ namespace: blueprint start ---------------------// void init_blueprint()noexcept; villageBlueprintId_t str_2_villageBlueprintId( const std::string &name_ )noexcept; void build_ecoObj_goDatasForCreate( villageBlueprintId_t villageId_, IntVec2 ecoObjMPos_, size_t ecoObjUWeight_, std::unordered_map<mapEntKey_t, std::unique_ptr<GoDataForCreate>> &majorGoDatasForCreate_, std::unordered_map<mapEntKey_t, std::unique_ptr<GoDataForCreate>> &floorGoDatasForCreate_, std::unordered_set<fieldKey_t> &artifactFieldKeys ); void build_natureYard_majorGoDatasForCreate( std::unordered_map<mapEntKey_t, std::unique_ptr<GoDataForCreate>> &majorGoDatasForCreate_, yardBlueprintId_t natureMajorYardId_, IntVec2 yardMPos_, size_t yard_uWeight_, std::function<bool(IntVec2)> f_is_mapent_in_bioSoup_ ); void build_natureYard_floorGoDatasForCreate( std::unordered_map<mapEntKey_t, std::unique_ptr<GoDataForCreate>> &floorGoDatasForCreate_, yardBlueprintId_t natureFloorYardId_, IntVec2 yardMPos_, size_t yard_uWeight_, std::function<bool(IntVec2)> f_is_correct_density_ ); }//--------------------- namespace: blueprint end ------------------------// #endif
turesnake/tprPixelGames
src/Engine/player/GameArchive.h
<gh_stars>100-1000 /* * ====================== GameArchive.h ======================= * -- tpr -- * CREATE -- 2019.04.29 * MODIFY -- * ---------------------------------------------------------- */ #ifndef TPR_GAME_ARCHIVE_H #define TPR_GAME_ARCHIVE_H //--- glm - 0.9.9.5 --- #include "glm_no_warnings.h" //-------------------- Engine --------------------// #include "IntVec.h" #include "ID_Manager.h" #include "gameArchiveId.h" #include "GameObjType.h" //-- 与 数据库 table_gameArchive 的结构 一致 class GameArchive{ public: gameArchiveId_t id {}; //- u32 存档id.目前版本中,只能是 1,2,3 uint32_t baseSeed {}; //- player.go - goid_t playerGoId {}; //- u64 glm::dvec2 playerGoDPos {}; //- double, double //- GameObj - goid_t maxGoId {}; //- u64 double gameTime {}; //- double //======== static ========// static ID_Manager id_manager; //- 负责生产 go_id ( 在.cpp文件中初始化 ) private: }; //============== static ===============// inline ID_Manager GameArchive::id_manager { ID_TYPE::U32, 1}; #endif
turesnake/tprPixelGames
src/Script/gameObjs/bioSoup/BioSoupParticle.h
/* * ==================== BioSoupParticle.h ========================== * -- tpr -- * CREATE -- 2020.03.06 * MODIFY -- * ---------------------------------------------------------- */ #ifndef TPR_GO_BIO_SOUP_PARTICLE_H #define TPR_GO_BIO_SOUP_PARTICLE_H //--- glm - 0.9.9.5 --- #include "glm_no_warnings.h" //-------------------- CPP --------------------// #include <cmath> #include <vector> #include <map> //-------------------- Engine --------------------// #include "tprAssert.h" #include "animSubspeciesId.h" #include "fieldFractType.h" #include "MapAltitude.h" #include "SignInMapEnts_Square_Type.h" //-------------------- Script --------------------// #include "Script/gameObjs/bioSoup/BioSoupState.h" namespace gameObjs::bioSoup {//------------- namespace gameObjs::bioSoup ---------------- class BioSoupParticle{ public: BioSoupParticle() { if( !BioSoupParticle::isStaticInit ){ BioSoupParticle::isStaticInit = true; BioSoupParticle::init_for_static(); } } inline void init( size_t uWeight_, State bioSoupState_, SignInMapEnts_Square_Type squType_, MapAltitude mpAlti_ )noexcept{ this->uWeight = uWeight_; this->bioSoupState = bioSoupState_; {// extraCreateStepDelay double d = static_cast<double>(std::abs(mpAlti_.get_val())) * 1.7; this->extraCreateStepDelay = static_cast<size_t>( std::floor(d) ); } //-- fieldFractType -- switch( squType_ ){ case SignInMapEnts_Square_Type::T_1m1: this->fieldFractType = FieldFractType::MapEnt; break; case SignInMapEnts_Square_Type::T_2m2: this->fieldFractType = FieldFractType::HalfField;break; case SignInMapEnts_Square_Type::T_4m4: this->fieldFractType = FieldFractType::Field; break; default: tprAssert(0); } {// animSubspeciesId size_t idx = (uWeight_ + 9976173) % BioSoupParticle::animSubspeciesIdSets.size(); this->animSubspeciesPtr = &BioSoupParticle::animSubspeciesIdSets.at(idx); } // goMesh_dposOffsPtr if( this->fieldFractType == FieldFractType::MapEnt ){ // do nothing }else if( this->fieldFractType == FieldFractType::HalfField ){ size_t idx = (uWeight_ + 9276115) % BioSoupParticle::goMeshDposOffSets_2m2.size(); this->goMeshDposOffsPtr = &BioSoupParticle::goMeshDposOffSets_2m2.at(idx); }else if( this->fieldFractType == FieldFractType::Field ){ size_t idx = (uWeight_ + 11976115) % BioSoupParticle::goMeshDposOffSets_4m4.size(); this->goMeshDposOffsPtr = &BioSoupParticle::goMeshDposOffSets_4m4.at(idx); }else{ tprAssert(0); } {// createStepsPtr size_t idx = (uWeight_ + 9976133) % BioSoupParticle::createStepSets.size(); this->createStepsPtr = &BioSoupParticle::createStepSets.at(idx); } } // 永远循环使用一组数据 inline const glm::dvec2 &get_next_goMeshDposOff()noexcept{ if( this->fieldFractType == FieldFractType::MapEnt ){ return BioSoupParticle::goMeshDposOff_1m1; }else{ this->goMeshDposOffCount++; if( this->goMeshDposOffCount >= this->goMeshDposOffsPtr->size() ){ this->goMeshDposOffCount = 0; } return this->goMeshDposOffsPtr->at( this->goMeshDposOffCount ); } } inline size_t get_next_createStep()noexcept{ this->createStepCount++; if( this->createStepCount >= this->createStepsPtr->size() ){ this->createStepCount = 0; } return this->createStepsPtr->at(this->createStepCount) + this->extraCreateStepDelay; } inline animSubspeciesId_t get_next_animSubspeciesId()noexcept{ this->animSubspecieCount++; if( this->animSubspecieCount >= this->animSubspeciesPtr->size() ){ this->animSubspecieCount = 0; } return this->animSubspeciesPtr->at(this->animSubspecieCount); } private: static void init_for_static(); size_t uWeight {}; State bioSoupState {}; // 暂时无用 FieldFractType fieldFractType {}; //-- 一个 biosoup 实例,分配到一份随机数据后,就不再变动了 std::vector<animSubspeciesId_t> *animSubspeciesPtr {nullptr}; size_t animSubspecieCount {0}; std::vector<glm::dvec2> *goMeshDposOffsPtr {nullptr}; size_t goMeshDposOffCount {0}; std::vector<size_t> *createStepsPtr {nullptr}; size_t createStepCount {0}; size_t extraCreateStepDelay {}; // 越远离 边界的 区域,生成 particle 越缓慢 //======= static =======// static bool isStaticInit; static std::vector<std::vector<animSubspeciesId_t>> animSubspeciesIdSets; // 若干份数据,每一份,都包含一组 打乱了次序的点,在这个点上 创建 particle-gomesh static constexpr glm::dvec2 goMeshDposOff_1m1 { 0.0, 0.0 }; static std::vector<std::vector<glm::dvec2>> goMeshDposOffSets_2m2; static std::vector<std::vector<glm::dvec2>> goMeshDposOffSets_4m4; static std::vector<std::vector<size_t>> createStepSets; }; }//------------- namespace gameObjs::bioSoup: end ---------------- #endif
turesnake/tprPixelGames
deps/tprInWin/tprFileSys_win.h
<gh_stars>100-1000 /* * ========================= tprFileSys_win.h ========================== * -- tpr -- * CREATE -- 2019.06.01 * MODIFY -- * ---------------------------------------------------------- * 简陋的 win平台 常用代码库 * ---------------------------- */ #ifndef TPR_FILE_SYS_WIN_H_ #define TPR_FILE_SYS_WIN_H_ #include <string> namespace tprWin {//--------------- namespace: tprWin -------------------// const std::string mk_dir(const std::string &path_dir_, const std::string &name_, const std::string &err_info_ ); int32_t file_load( const std::string &path_, std::string &buf_); }//--------------- namespace: tprWin end -------------------// #endif
turesnake/tprPixelGames
src/Engine/resource/esrc_uniformBlockObj.h
/* * =================== esrc_uniformBlockObj.h ========================== * -- tpr -- * CREATE -- 2019.09.23 * MODIFY -- * ---------------------------------------------------------- */ #ifndef TPR_ESRC_UNIFORM_BLOCK_OBJ_H #define TPR_ESRC_UNIFORM_BLOCK_OBJ_H //-------------------- Engine --------------------// #include "UniformBlockObj.h" #include "uniformBlockObjs.h" namespace esrc {//------------------ namespace: esrc -------------------------// void init_uniformBlockObjs()noexcept; //-- must before esrc::init_shaders() !!! ubo::UniformBlockObj &get_uniformBlockObjRef( ubo::UBOType type_ )noexcept; }//---------------------- namespace: esrc -------------------------// #endif
turesnake/tprPixelGames
src/Engine/VAOVBO/VAOVBO.h
/* * ========================= VAOVBO.h ========================== * -- tpr -- * CREATE -- 2018.12.24 * MODIFY -- * ---------------------------------------------------------- * used for most of meshs/goMeshs * excep groundGo meshs * ---------------------------- */ #ifndef TPR_VAO_VBO_H #define TPR_VAO_VBO_H //=== *** glad FIRST, glfw SECEND *** === // Don't include glfw3.h ALONE!!! #include <glad/glad.h> class VAOVBO{ public: VAOVBO()=default; ~VAOVBO(){ glDeleteVertexArrays( 1, &this->VAO ); glDeleteBuffers( 1, &this->VBO ); } void init(const GLvoid *pointsPtr_, GLsizeiptr vboSize_ )noexcept; // can be copy and hold by caller inline GLuint get_VAO()const noexcept{ return this->VAO; } private: GLuint VAO {}; //- obj id GLuint VBO {}; //- obj id }; #endif
turesnake/tprPixelGames
src/Script/json/json_all.h
/* * ======================== json_all.h ========================== * -- tpr -- * 创建 -- 2019.09.29 * 修改 -- * ---------------------------------------------------------- */ #ifndef TPR_JSON_ALL_H #define TPR_JSON_ALL_H //-------------------- Engine --------------------// #include "GameObj.h" namespace json{//------------- namespace json ---------------- //------------------------------// void parse_colorTableJsonFile(); void parse_ecoSysPlansJsonFile(); //------------------------------// // json_windowConfig //------------------------------// class WindowConfigJsonData{ public: int windowPixW {}; int windowPixH {}; bool isFullScreen {}; //... }; WindowConfigJsonData parse_windowConfigJsonFile(); }//------------- namespace json: end ---------------- #endif
turesnake/tprPixelGames
src/Engine/gameObj/GoFunctorSet.h
<filename>src/Engine/gameObj/GoFunctorSet.h<gh_stars>100-1000 /* * ====================== GoFunctorSet.h ========================== * -- tpr -- * CREATE -- 2020.02.12 * MODIFY -- * ---------------------------------------------------------- */ #ifndef TPR_GO_FUNCTOR_SET_H #define TPR_GO_FUNCTOR_SET_H //-------------------- CPP --------------------// #include <unordered_map> #include <functional> //-------------------- Engine --------------------// #include "tprAssert.h" #include "DyFunctor.h" #include "GoFunctorLabel.h" class GoFunctorSet{ public: GoFunctorSet()=default; template<typename T> inline void insert( GoFunctorLabel label_, T functor_ )noexcept{ auto [insertIt, insertBool] = this->functors.emplace( label_, DyFunctor{} ); tprAssert( insertBool ); DyFunctor &f = insertIt->second; //--- f.init<T>( functor_ ); } // 返回值是 std::funtion<> 的 ref template<typename T> inline T &get( GoFunctorLabel label_ )noexcept{ tprAssert( this->functors.find(label_) != this->functors.end() ); DyFunctor &f = this->functors.at(label_); //--- return *(f.get<T>()); } private: std::unordered_map<GoFunctorLabel, DyFunctor> functors {}; }; #endif
turesnake/tprPixelGames
deps/tprInUnix/tprFileSys_unix.h
<filename>deps/tprInUnix/tprFileSys_unix.h /* * ========================= tprFileSys_unix.h ========================== * -- tpr -- * CREATE -- 2018.10.14 * MODIFY -- * ---------------------------------------------------------- * 专门存放 文件系统 相关的 函数 * ---------------------------- */ #ifndef TPR_FILESYS_UNIX_H_ #define TPR_FILESYS_UNIX_H_ #include <string> namespace tprUnix {//--------------- namespace: tprUnix -------------------// int check_st_mode( mode_t mode_ ); int check_path_st_mode( const char *path_ ); int check_path_st_mode( int fd_ ); bool is_path_valid( const char *path_ ); bool is_path_valid( int fd_ ); void Is_path_valid( const char *path_, const std::string &err_info_ ); void Is_path_valid( int fd_, const std::string &err_info_ ); int is_path_a_dir( const char *path_ ); int is_path_a_dir( int fd_ ); void Is_path_a_dir( const char *path_, const std::string &err_info_ ); void Is_path_a_dir( int fd_, const std::string &err_info_ ); void mk_dir( const char *path_, mode_t mode_, const std::string &err_info_ ); const std::string mk_dir( const std::string &_path_dir, const std::string &name_, mode_t mode_, const std::string &err_info_ ); void mk_dir( int fd_, const char * name_, mode_t mode_, const std::string &err_info_ ); /* const std::string path_combine( const std::string &_pa, const std::string &_pb ); const std::string path_combine( const char *_pa, const char *_pb ); */ /* const std::string nameString_combine( const std::string &_prefix, size_t _idx, const std::string &_suffix ); */ bool is_path_not_too_long( const std::string &path_ ); void Is_path_not_too_long( const std::string &path_, const std::string &err_info_ ); off_t get_file_size( int fd_, const std::string &err_info_ ); //off_t get_file_size( FILE *_fp, const std::string &err_info_ ); off_t get_file_size( const char *path_, const std::string &err_info_ ); void file_load( const std::string &path_, std::string &_buf ); }//------------------- namespace: tprUnix ------------------------// #endif
turesnake/tprPixelGames
src/Engine/collision/ColliDataFromJson.h
<filename>src/Engine/collision/ColliDataFromJson.h /* * ===================== ColliDataFromJson.h ========================== * -- tpr -- * CREATE -- 2019.09.19 * MODIFY -- * ---------------------------------------------------------- * 从 Jpng 读取的 colli 数据 */ #ifndef TPR_COLLI_DATA_FROM_JPNG_H #define TPR_COLLI_DATA_FROM_JPNG_H #include "pch.h" //-------------------- Engine --------------------// #include "GoAltiRange.h" #include "ColliderType.h" #include "SignInMapEnts_Square_Type.h" // 可能要改名为 FromJson class ColliDataFromJson{ public: ColliDataFromJson()=default; virtual ~ColliDataFromJson()=default; //--- virtual ColliderType get_colliderType()const =0; virtual double get_moveColliRadius()const =0; virtual double get_skillColliRadius()const =0; virtual const std::vector<glm::dvec2> &get_colliPointDPosOffs()const =0; //--- only support in circular --- virtual Circular calc_circular( const glm::dvec2 &goCurrentDPos_, CollideFamily family_ ) const = 0; //--- only support in square --- virtual Square calc_square( const glm::dvec2 &goCurrentDPos_ )const = 0; virtual SignInMapEnts_Square_Type get_signInMapEnts_square_type()const = 0; }; class ColliDataFromJson_Nil : public ColliDataFromJson{ public: ColliDataFromJson_Nil(): colliderType(ColliderType::Nil) {} //----- get -----// inline ColliderType get_colliderType()const override{ return this->colliderType; } //---- not exist funcs ----// inline double get_moveColliRadius() const override{ //- not exist tprAssert(0); return 0.0; } inline double get_skillColliRadius() const override{ //- not exist tprAssert(0); return 0.0; } inline const std::vector<glm::dvec2> &get_colliPointDPosOffs() const override{ //- not exist tprAssert(0); return ColliDataFromJson_Nil::emptyVec; } inline Circular calc_circular( const glm::dvec2 &goCurrentDPos_, CollideFamily family_ )const override{ //- not exist tprAssert(0); return Circular{}; } inline Square calc_square( const glm::dvec2 &goCurrentDPos_ )const override{ //- not exist tprAssert(0); return Square{}; } inline SignInMapEnts_Square_Type get_signInMapEnts_square_type()const override{ tprAssert(0); return SignInMapEnts_Square_Type::T_1m1; } //----- vals -----// ColliderType colliderType {}; //- nil/cir/cap 一经初始,用不改变 //===== static =====// static std::vector<glm::dvec2> emptyVec; static std::unique_ptr<ColliDataFromJson> nillInstance; // 一些类似 groundGo 的go,无法通过标准流程被组件,但也需要一个 Nil类型的 ColliDataFromJson 数据 // 此处提供给它们一个 通用的 实例 }; class ColliDataFromJson_Circular : public ColliDataFromJson{ public: ColliDataFromJson_Circular(): colliderType(ColliderType::Circular) {} inline void makeSure_colliPointDPosOffs_isNotEmpty()const noexcept{ tprAssert( !this->colliPointDPosOffs.empty() ); } inline Circular calc_circular(const glm::dvec2 &goCurrentDPos_, CollideFamily family_ )const override{ double radius {}; if( family_ == CollideFamily::Move ){ radius = this->moveColliRadius; }else{ radius = this->skillColliRadius; } return Circular{ goCurrentDPos_, radius }; } //----- get virtual -----// inline ColliderType get_colliderType()const override{ return this->colliderType; } inline double get_moveColliRadius() const override{ return this->moveColliRadius; } inline double get_skillColliRadius() const override{ return this->skillColliRadius; } inline const std::vector<glm::dvec2> &get_colliPointDPosOffs() const override{ return this->colliPointDPosOffs; } //---- not exist funcs ----// inline Square calc_square( const glm::dvec2 &goCurrentDPos_ )const override{ //- not exist tprAssert(0); return Square{}; } inline SignInMapEnts_Square_Type get_signInMapEnts_square_type()const override{ tprAssert(0); return SignInMapEnts_Square_Type::T_1m1; } //----- vals -----// ColliderType colliderType {}; //- nil/cir/cap 一经初始,用不改变 double moveColliRadius {}; double skillColliRadius {}; std::vector<glm::dvec2> colliPointDPosOffs {};//- 移动碰撞检测点,会被自动生成 //===== static =====// }; class ColliDataFromJson_Square : public ColliDataFromJson{ public: ColliDataFromJson_Square(): colliderType(ColliderType::Square) {} //----- get -----// inline ColliderType get_colliderType()const override{ return this->colliderType; } inline const std::vector<glm::dvec2> &get_colliPointDPosOffs() const override{ return ColliDataFromJson_Square::colliPointDPosOffs; } inline Square calc_square( const glm::dvec2 &goCurrentDPos_ )const override{ return Square{ goCurrentDPos_ }; } inline SignInMapEnts_Square_Type get_signInMapEnts_square_type()const override{ return this->signInMapEnts_square_type; } //---- not exist funcs ----// inline double get_moveColliRadius() const override{ //- not exist tprAssert(0); return 0.0; } inline double get_skillColliRadius() const override{ //- not exist tprAssert(0); return 0.0; } inline Circular calc_circular( const glm::dvec2 &goCurrentDPos_, CollideFamily family_ )const override{ //- not exist tprAssert(0); return Circular{}; } static void init_for_static()noexcept; // MUST CALL IN MAIN !!! //----- vals -----// ColliderType colliderType {}; //- nil/cir/cap 一经初始,用不改变 SignInMapEnts_Square_Type signInMapEnts_square_type {}; //===== static =====// static std::vector<glm::dvec2> colliPointDPosOffs;//- 移动碰撞检测点,只有一套,所有实例通用 }; #endif
turesnake/tprPixelGames
src/Engine/gameObj/FloorGoType.h
/* * ====================== FloorGoType.h ========================== * -- tpr -- * CREATE -- 2019.12.08 * MODIFY -- * ---------------------------------------------------------- */ #ifndef TPR_GO_FLOOR_GO_TYPE_H #define TPR_GO_FLOOR_GO_TYPE_H //--- glm - 0.9.9.5 --- #include "glm_no_warnings.h" //-------------------- CPP --------------------// #include <cmath> #include <string> #include "config.h" #include "tprAssert.h" #include "tprMath.h" enum class FloorGoSize{ MapEnt_2m2, MapEnt_3m3, MapEnt_4m4, }; FloorGoSize str_2_floorGoSize( const std::string &str_ )noexcept; // 计算某种 floorGo,从其 中点dpos,到 中点所在的 mpos 的 偏移值 inline glm::dvec2 calc_floorGo_mid_dposOff( FloorGoSize size_ )noexcept{ switch (size_){ case FloorGoSize::MapEnt_2m2: return glm::dvec2{ 0.0, 0.0 }; case FloorGoSize::MapEnt_3m3: return glm::dvec2{ HALF_PIXES_PER_MAPENT_D, HALF_PIXES_PER_MAPENT_D }; case FloorGoSize::MapEnt_4m4: return glm::dvec2{ 0.0, 0.0 }; default: tprAssert(0); return glm::dvec2{}; break; } } // floorGo 的渲染层次,本值影响 floorGo.goMeshZOff 值 // 在 蓝图 FD.png 数据中 // --- // 这样,我们就能实现: // 地面拥有最基础的 nature 层 floorgo:L_0 // 在此之上,可以为房间内铺设地板:L_1 // 在地板上,可以铺设地毯:L_2 enum class FloorGoLayer{ L_0, // goMeshZOff: (0.0, 0.1) (BOTTOM). 普通 fgo / nature fgo,大部分 road-fgo,都属于此 L_1, // goMeshZOff: (0.1, 0.2) 地板 L_2, // goMeshZOff: (0.2, 0.3) 地毯 L_3, // goMeshZOff: (0.3, 0.4) L_4, // goMeshZOff: (0.4, 0.5) (TOP) }; inline double floorGoLayer_2_goMesh_baseZOff( FloorGoLayer layer_ )noexcept{ switch (layer_){ case FloorGoLayer::L_0: return 0.0; case FloorGoLayer::L_1: return 0.1; case FloorGoLayer::L_2: return 0.2; case FloorGoLayer::L_3: return 0.3; case FloorGoLayer::L_4: return 0.4; default: tprAssert(0); return 0.0; // never reach } } FloorGoLayer str_2_floorGoLayer( const std::string &str_ )noexcept; inline double calc_floorGoMesh_zOff( FloorGoLayer layer_, size_t mapEntUWeight_ )noexcept{ // 获得一个 小数值 (0.0, 0.1) double fract = calc_uWeight_fractValue(mapEntUWeight_) / 10.0; return ( floorGoLayer_2_goMesh_baseZOff(layer_) + fract ); } #endif
turesnake/tprPixelGames
src/Engine/animFrameSet/calc_colliPoints.h
<filename>src/Engine/animFrameSet/calc_colliPoints.h<gh_stars>100-1000 /* * ===================== calc_colliPoints.h ========================== * -- tpr -- * CREATE -- 2019.11.17 * MODIFY -- * ---------------------------------------------------------- */ #ifndef TPR_CALC_COLLI_POINTS_H #define TPR_CALC_COLLI_POINTS_H #include "pch.h" void calc_colliPoints_for_circular( std::vector<glm::dvec2> &container_, double radius_ ); const std::vector<glm::dvec2> &get_colliPointDPosOffsRef_for_cirDogo()noexcept; #endif
turesnake/tprPixelGames
src/Script/gameObjs/allGoes.h
/* * ========================= allGoes.h ========================== * -- tpr -- * CREATE -- 2019.04.13 * MODIFY -- * ---------------------------------------------------------- * 游戏中全体 go 具象类 h文件 include * ---------------------------- */ #ifndef TPR_ALL_GOES_H #define TPR_ALL_GOES_H //---------- Script : gameObjs : majorGos -------------// //#include "Script/gameObjs/majorGos/Norman.h" //#include "Script/gameObjs/majorGos/BigMan.h" #include "Script/gameObjs/oth/PlayerGoCircle.h" #include "Script/gameObjs/majorGos/chicken/Chicken.h" #include "Script/gameObjs/majorGos/HollowLog.h" //---------- Script : gameObjs : bioSoup --------------------// #include "Script/gameObjs/bioSoup/BioSoup.h" //---------- Script : gameObjs : artifacts -------------// #include "Script/gameObjs/majorGos/artifacts/Fence.h" #include "Script/gameObjs/majorGos/artifacts/Firewood.h" #include "Script/gameObjs/majorGos/artifacts/StoneWall.h" #include "Script/gameObjs/majorGos/artifacts/campfire/Campfire.h" #include "Script/gameObjs/majorGos/artifacts/glassBottle/GlassBottle.h" #include "Script/gameObjs/majorGos/artifacts/Pot.h" #include "Script/gameObjs/majorGos/artifacts/trough/Trough.h" //---------- Script : gameObjs : bush --------------------// //#include "Script/gameObjs/bush/Wheat.h" #include "Script/gameObjs/majorGos/bushs/Mushroom.h" #include "Script/gameObjs/majorGos/bushs/Bush.h" //---------- Script : gameObjs : majorGos : trees -------------// //#include "Script/gameObjs/majorGos/trees/OakTree.h" #include "Script/gameObjs/majorGos/trees/Cactus.h" #include "Script/gameObjs/majorGos/trees/FigTree.h" #include "Script/gameObjs/majorGos/trees/PineTree.h" #include "Script/gameObjs/majorGos/trees/PoplarTree.h" //---------- Script : gameObjs : majorGos : rocks -------------// #include "Script/gameObjs/majorGos/rocks/Rock.h" #include "Script/gameObjs/majorGos/rocks/BreakStone.h" //---------- Script : gameObjs : floorGos --------------------// #include "Script/gameObjs/floorGos/FloorGo.h" #include "Script/gameObjs/oth/GroundGo.h" #include "Script/gameObjs/oth/FieldRim.h" #include "Script/gameObjs/majorGos/Grass.h" #endif
turesnake/tprPixelGames
src/Engine/resource/esrc_field.h
<gh_stars>100-1000 /* * ========================= esrc_field.h ========================== * -- tpr -- * CREATE -- 2019.04.19 * MODIFY -- * ---------------------------------------------------------- */ #ifndef TPR_ESRC_FIELD_H #define TPR_ESRC_FIELD_H //-------------------- CPP --------------------// #include <utility> //- pair #include <memory> #include <unordered_map> #include <optional> //-------------------- Engine --------------------// #include "MapField.h" #include "fieldKey.h" namespace esrc {//------------------ namespace: esrc -------------------------// void init_fields(); void move_fieldUPtrs( std::unordered_map<fieldKey_t, std::unique_ptr<MapField>> &fields_ ); void erase_all_fields_in_chunk( IntVec2 chunkMPos_ ); std::optional<const MapField*> get_fieldPtr( fieldKey_t fieldKey_ ); }//---------------------- namespace: esrc -------------------------// #endif
turesnake/tprPixelGames
src/Engine/mesh/ChildMesh.h
/* * ========================= ChildMesh.h ========================== * -- tpr -- * CREATE -- 2019.01.22 * MODIFY -- * ---------------------------------------------------------- */ #ifndef TPR_CHILD_MESH_H #define TPR_CHILD_MESH_H //--- glm - 0.9.9.5 --- #include "glm_no_warnings.h" //-------------------- Engine --------------------// #include "ShaderProgram.h" //-- each GameObjMesh instance,will bind a shader #include "ViewingBox.h" #include "functorTypes.h" //--- need ---// class GameObjMesh; //-- pic/shadow 共用一套结构 --// // 这个 class 应尽可能地 轻量化,让公共数据,放到 GoMesh 中 class ChildMesh{ public: ChildMesh( bool isPic_, GameObjMesh &goMeshRef_ ): goMeshRef(goMeshRef_), isPic(isPic_) { this->init(); } void init()noexcept; void draw(); inline void set_shader_program( ShaderProgram *sp_ ) noexcept{ this->shaderPtr=sp_; } //inline void bind_before_drawCall( F_void f_ ){ this->before_drawCall = f_; } //-- 此函数 只能在 RenderUpdate 阶段被调用 -- //-- 其余代码 不应随意调用 此函数!!! -- void refresh_translate(); //- 大部分 具象go实例 的 goMesh图元 长宽值 与 AnimFrameSet数据 强关联 -- // 所以可以直接从 AnimFrameSet 中获取数据 // 这个函数很常用 // 但如果 AnimFrameSet实例 并不更换,也没必要 每1视觉帧 都执行此函数 void refresh_scale_auto(); inline ChildMesh *getnc_ChildMeshPtr()noexcept{ return const_cast<ChildMesh*>(this); } //- 通过 translate_val.z 值 来给 待渲染的 meshs 排序 -- inline float get_render_z()const noexcept{ return this->translate_val.z; } //-- 外部 debug 用 inline const glm::vec3 &get_translate_val()const noexcept{ return this->translate_val; } private: void update_mat4_model(); //-- 重新计算 model矩阵 //======== vals ========// GameObjMesh &goMeshRef; 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::vec2 scale_frameSZ {glm::vec2(1.0f, 1.0f)}; //- 仅仅表达 图元帧 的缩放比例 glm::vec3 scale_total {glm::vec3(1.0f, 1.0f, 1.0f)}; //- 最终传入 mat4 的值 //----- functor -----// // not used yet ... //F_void before_drawCall {nullptr}; // call back. e.g. do some shader uniform bind //======== flags ========// bool isPic {true}; //-- pic / shadow }; #endif
turesnake/tprPixelGames
src/Engine/ecoSys/EcoSysPlanType.h
<reponame>turesnake/tprPixelGames<filename>src/Engine/ecoSys/EcoSysPlanType.h /* * ====================== EcoSysPlanType.h ======================= * -- tpr -- * CREATE -- 2019.02.22 * MODIFY -- * ---------------------------------------------------------- * ecosystem plan type * ---------------------------- */ #ifndef TPR_ECOSYS_PLAN_TYPE_H #define TPR_ECOSYS_PLAN_TYPE_H //------------------- C --------------------// #include <cstddef> //- size_t //------------------- CPP --------------------// #include <string> #include <cstdint> // uint8_t //------------------- Engine --------------------// #include "tprAssert.h" using ecoSysPlanId_t = uint32_t; //- 每一个type,都存在数个变种 enum class EcoSysPlanType : uint32_t{ BegIdx = 0, //- 通过此值来计算 第一个 typeIdx 是多少。 //-- 确保所有 type 连续存放 -- Forest, DarkForest, Savannah, Desert, //---- EndIdx //- 通过此值来计算 最后一个 typeIdx 是多少。 }; inline size_t ecoSysPlanType_2_size_t( EcoSysPlanType type_ )noexcept{ return static_cast<size_t>(type_); } inline const size_t EcoSysPlanType_MinIdx { ecoSysPlanType_2_size_t(EcoSysPlanType::BegIdx) + 1 }; //- 最小序号 inline const size_t EcoSysPlanType_MaxIdx { ecoSysPlanType_2_size_t(EcoSysPlanType::EndIdx) - 1 }; //- 最大序号 inline const size_t EcoSysPlanType_Num { EcoSysPlanType_MaxIdx - EcoSysPlanType_MinIdx + 1 }; //- type 个数 //-- 用来遍历 某些复合容器 -- inline size_t ecoSysPlanType_2_idx( EcoSysPlanType type_ )noexcept{ return (ecoSysPlanType_2_size_t(type_) - EcoSysPlanType_MinIdx); } EcoSysPlanType str_2_ecoSysPlanType( const std::string &str_ )noexcept; #endif
turesnake/tprPixelGames
src/Engine/sys/config.h
/* * ========================= config.h ========================== * -- tpr -- * CREATE -- 2018.11.21 * MODIFY -- * ---------------------------------------------------------- * config_Vals about pixel and gameMapSize */ #ifndef TPR_CONFIG_H #define TPR_CONFIG_H //-- 一个 section,占有 4*4 chunks template<typename T = int> constexpr T CHUNKS_PER_SECTION {4}; //-- 一个 chunk,占有 8*8 fields template<typename T = int> constexpr T FIELDS_PER_CHUNK {8}; template<typename T = int> constexpr T FIELDS_PER_SECTION { FIELDS_PER_CHUNK<> * CHUNKS_PER_SECTION<> }; //-- 一个 field,占有 4*4 mapents template<typename T = int> constexpr T ENTS_PER_FIELD {4}; template<typename T = int> constexpr T HALF_ENTS_PER_FIELD { ENTS_PER_FIELD<> / 2 }; //-- 一个 mapent 占用 64 * 64 像素 template<typename T = int> constexpr T PIXES_PER_MAPENT {64}; template<typename T = int> constexpr T HALF_PIXES_PER_MAPENT { PIXES_PER_MAPENT<> / 2 }; //-- 一个 chunk,占有 32*32 mapents template<typename T = int> constexpr T ENTS_PER_CHUNK { FIELDS_PER_CHUNK<> * ENTS_PER_FIELD<> }; //-- 一个 section,占有 128*128 mapEnts template<typename T = int> constexpr T ENTS_PER_SECTION { ENTS_PER_CHUNK<> * CHUNKS_PER_SECTION<> }; template<typename T = int> constexpr T HALF_ENTS_PER_SECTION { ENTS_PER_SECTION<> / 2 }; //-- 一个 field,占有 32*32 pixel template<typename T = int> constexpr T PIXES_PER_FIELD { ENTS_PER_FIELD<> * PIXES_PER_MAPENT<> }; template<typename T = int> constexpr T HALF_PIXES_PER_FIELD { PIXES_PER_FIELD<> / 2 }; //-- 一个 chunk,占有 256*256 pixel template<typename T = int> constexpr T PIXES_PER_CHUNK { ENTS_PER_CHUNK<> * PIXES_PER_MAPENT<> }; //-- 为避免渲染时,chunk间出现白线,而做的 补偿措施 “每个chunk 多渲一排pix,相互叠加” -- template<typename T = int> constexpr T PIXES_PER_CHUNK_IN_TEXTURE { PIXES_PER_CHUNK<> + 1 }; //-- 一个 section,占有 1024*1024 pixel template<typename T = int> constexpr T PIXES_PER_SECTION { CHUNKS_PER_SECTION<> * PIXES_PER_CHUNK<> }; //-- camera.viewingBox z_deep template<typename T = int> constexpr T VIEWING_BOX_Z_DEEP {10000}; //====== double ====== constexpr double PIXES_PER_MAPENT_D { static_cast<double>(PIXES_PER_MAPENT<>) }; constexpr double HALF_PIXES_PER_MAPENT_D { static_cast<double>(HALF_PIXES_PER_MAPENT<>) }; constexpr double PIXES_PER_FIELD_D { static_cast<double>(PIXES_PER_FIELD<>) }; constexpr double HALF_PIXES_PER_FIELD_D { static_cast<double>(HALF_PIXES_PER_FIELD<>) }; constexpr double ENTS_PER_CHUNK_D { static_cast<double>(ENTS_PER_CHUNK<>) }; constexpr double ENTS_PER_FIELD_D { static_cast<double>(ENTS_PER_FIELD<>) }; constexpr double HALF_ENTS_PER_FIELD_D { static_cast<double>(HALF_ENTS_PER_FIELD<>) }; constexpr double ENTS_PER_SECTION_D { static_cast<double>(ENTS_PER_SECTION<>) }; constexpr double PIXES_PER_CHUNK_D { static_cast<double>(PIXES_PER_CHUNK<>) }; constexpr float PIXES_PER_CHUNK_F { static_cast<float>(PIXES_PER_CHUNK<>) }; #endif
turesnake/tprPixelGames
src/Engine/map/Quad.h
/* * ========================== Quad.h ======================= * -- tpr -- * CREATE -- 2019.03.03 * MODIFY -- * ---------------------------------------------------------- * quadrant * ---------------------------- */ #ifndef TPR_QUAD_H #define TPR_QUAD_H //-------------------- Engine --------------------// #include "tprAssert.h" //-- 一共有 4个 扇区 -- #define QUAD_NUM 4 //-- 4个象限类型,[left-bottom] -- // 排列顺序是为了 方便地遍历 vector enum class QuadType : int { Left_Bottom = 0, Right_Bottom = 1, Left_Top = 2, Right_Top = 3 }; inline int QuadType_2_Idx( QuadType type_ )noexcept{ return (int)type_; } inline QuadType QuadIdx_2_Type( int idx_ )noexcept{ switch(idx_){ case 0: return QuadType::Left_Bottom; case 1: return QuadType::Right_Bottom; case 2: return QuadType::Left_Top; case 3: return QuadType::Right_Top; default: tprAssert(0); return QuadType::Left_Bottom; //- never touch } } //--- 统一管理 4个象限的 bool值 --- // 暂时未被使用 class QuadFlag{ public: explicit QuadFlag( bool val_=false ): is_left_bottom(val_), is_right_bottom(val_), is_left_top(val_), is_right_top(val_) {} inline bool is_all_true() const noexcept{ return( is_left_bottom && is_right_bottom && is_left_top && is_right_top ); } inline bool is_all_false() const noexcept{ return ( (is_left_bottom==false) && (is_right_bottom==false) && (is_left_top==false) && (is_right_top==false) ); } //======== flags ========// bool is_left_bottom {false}; bool is_right_bottom {false}; bool is_left_top {false}; bool is_right_top {false}; }; #endif
turesnake/tprPixelGames
src/Engine/gameObj/GoMemState.h
/* * ======================== GoMemState.h ======================= * -- tpr -- * CREATE -- 2019.07.17 * MODIFY -- * ---------------------------------------------------------- */ #ifndef TPR_GO_MEM_STATE_H #define TPR_GO_MEM_STATE_H // go 在游戏运行期间的 所有状态 // --- // 在目前版本中,一个go,一旦进入 WaitForRelease,将永不能被取回。 // 如果发现,想要新建的 go,正在 WaitForRelease 状态,说明参数设置有问题,直接报错。 // 这能简化很多 问题 // --- // 每一渲染帧,renderPool 会重新加载 active态的 go,并排序 // 当把一个 go,改成 WaitForRelease,它就已经无法被渲染出来了。 // // --- // 有必要再添加一个 WaitForDB ... // enum class GoMemState : int{ NotExist, OnCreating, Active, WaitForRelease, OnReleasing }; #endif
turesnake/tprPixelGames
src/Engine/map/MapEnt.h
<filename>src/Engine/map/MapEnt.h /* * ====================== MapEnt.h ======================= * -- tpr -- * CREATE -- 2018.12.09 * MODIFY -- * ---------------------------------------------------------- */ #ifndef TPR_MAP_ENT_H #define TPR_MAP_ENT_H #include "pch.h" //-------------------- Engine --------------------// #include "GoAltiRange.h" #include "MapCoord.h" #include "chunkKey.h" #include "EcoSysPlanType.h" #include "MapAltitude.h" #include "GameObjType.h" #include "ColliderType.h" #include "sectionKey.h" #include "colorTableId.h" #include "Density.h" //-------------------- Script --------------------// #include "Script/gameObjs/bioSoup/BioSoupState.h" //-- 64*64 pixes -- class MemMapEnt{ public: //-- 临时测试用 MemMapEnt( IntVec2 mpos_, chunkKey_t chunkKey_, sectionKey_t ecoObjKey_, colorTableId_t colorTableId_, Density density_, MapAltitude mapAlti_, gameObjs::bioSoup::State bioSoupState_, double uWeight_, bool isEcoBorder_ ): mpos(mpos_), chunkKey(chunkKey_), ecoObjKey(ecoObjKey_), colorTableId(colorTableId_), density(density_), mapAlti(mapAlti_), bioSoupState(bioSoupState_), uWeight(uWeight_), isEcoBorder(isEcoBorder_) {} inline void insert_2_circular_goids( goid_t goid_, ColliderType colliType_ )noexcept{ tprAssert( colliType_ == ColliderType::Circular ); auto [insertIt1, insertBool1] = this->majorGos_circular.insert( goid_ ); tprAssert( insertBool1 ); //-- auto [insertIt2, insertBool2] = this->majorGos.insert( goid_ ); tprAssert( insertBool2 ); } inline void erase_from_circular_goids( goid_t goid_, ColliderType colliType_ )noexcept{ tprAssert( colliType_ == ColliderType::Circular ); size_t eraseNum = this->majorGos_circular.erase(goid_); tprAssert( eraseNum == 1 ); //-- eraseNum = this->majorGos.erase(goid_); tprAssert( eraseNum == 1 ); } inline void set_square_goid( goid_t goid_, ColliderType colliType_ )noexcept{ tprAssert( colliType_ == ColliderType::Square ); tprAssert( this->majorGo_square == 0 ); // 一定要先合法地释放掉旧元素后,再登记新元素。禁止直接覆盖! this->majorGo_square = goid_; //-- auto [insertIt, insertBool] = this->majorGos.insert( goid_ ); tprAssert( insertBool ); } //- 当一个 squGo 被杀死时,才会被调用 // 自动释放一个 chunk 时,并不需要调用此函数 inline void erase_square_goid( goid_t goid_, ColliderType colliType_ )noexcept{ tprAssert( colliType_ == ColliderType::Square ); tprAssert( goid_ == this->majorGo_square ); this->majorGo_square = 0; // null //-- size_t eraseNum = this->majorGos.erase(goid_); tprAssert( eraseNum == 1 ); } inline void set_bioSoup_goid( goid_t goid_, GameObjFamily family_ )noexcept{ tprAssert( family_ == GameObjFamily::BioSoup ); if( this->bioSoupGo != 0 ){ tprDebug::console("bioSoupGo = {}", this->bioSoupGo ); } tprAssert( this->bioSoupGo == 0 ); // 一定要先合法地释放掉旧元素后,再登记新元素。禁止直接覆盖! this->bioSoupGo = goid_; //-- auto [insertIt, insertBool] = this->majorGos.insert( goid_ ); tprAssert( insertBool ); } //- 当一个 bioSoupGo 被杀死时,才会被调用 // 自动释放一个 chunk 时,并不需要调用此函数 inline void erase_bioSoup_goid( goid_t goid_, GameObjFamily family_ )noexcept{ tprAssert( family_ == GameObjFamily::BioSoup ); tprAssert( goid_ == this->bioSoupGo ); this->bioSoupGo = 0; // null //-- size_t eraseNum = this->majorGos.erase(goid_); tprAssert( eraseNum == 1 ); } //---------- get ----------// inline IntVec2 get_mpos()const noexcept{ return this->mpos;} inline MapAltitude get_mapAlti()const noexcept{ return this->mapAlti; } inline chunkKey_t get_chunkKey() const noexcept{ return this->chunkKey; } inline sectionKey_t get_ecoObjKey() const noexcept{ return this->ecoObjKey; } inline colorTableId_t get_colorTableId()const noexcept{ return this->colorTableId; } inline size_t get_uWeight()const noexcept{ return this->uWeight; } inline bool get_isEcoBorder()const noexcept{ return this->isEcoBorder; } inline Density get_density()const noexcept{ return this->density; } inline const std::unordered_set<goid_t> &get_goids()const noexcept{return this->majorGos; } inline const std::unordered_set<goid_t> &get_circular_goids()const noexcept{return this->majorGos_circular; } inline goid_t get_square_goid()const noexcept{ return this->majorGo_square; } inline goid_t get_bioSoup_goid()const noexcept{ return this->bioSoupGo; } private: // 以下这组成员,统一在 构造函数中被 init IntVec2 mpos; chunkKey_t chunkKey; sectionKey_t ecoObjKey; colorTableId_t colorTableId; // same as ecoObj.colorTableId Density density; MapAltitude mapAlti; //- 本 mapent 中点pix 的 alti gameObjs::bioSoup::State bioSoupState; size_t uWeight; // [0, 9999] bool isEcoBorder; // 在未来,将被拓展为 一个 具体的数字,表示自己离 border 的距离(mapents)... // signed goes // 支持 move/skill 碰撞检测 std::unordered_set<goid_t> majorGos {}; // cir + squ std::unordered_set<goid_t> majorGos_circular {}; goid_t majorGo_square {}; // only one // 一个 mapent 其实还允许出现 floorGo // 但是它们不是 majorGo,不参与游戏交互。 // 所以不会被登记到 mapent 中 goid_t bioSoupGo {0}; // only one // 一个 mapent 允许同时含有 一个 mp-go, 一个 bioSoup }; #endif
turesnake/tprPixelGames
src/Engine/map/mapEntKey.h
/* * ====================== mapEntKey.h ======================= * -- tpr -- * CREATE -- 2019.11.16 * MODIFY -- * ---------------------------------------------------------- * mapEnt "id": (int)w + (int)h * ---------------------------- */ #ifndef TPR_MAPENT_KEY_H #define TPR_MAPENT_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 mapEntKey_t = uint64_t; inline mapEntKey_t mpos_2_key( IntVec2 mpos_ )noexcept{ mapEntKey_t key {}; int *ptr = (int*)(&key); //- can't use static_cast<> *ptr = mpos_.x; ptr++; *ptr = mpos_.y; //-------- return key; } inline IntVec2 mapEntKey_2_mpos( mapEntKey_t key_ )noexcept{ IntVec2 mpos {}; int *ptr = (int*)&key_; //- can't use static_cast<> //--- mpos.x = *ptr; ptr++; mpos.y = *ptr; //--- return mpos; } #endif
turesnake/tprPixelGames
src/Script/gameObjs/floorGos/FloorGo.h
/* * ========================= FloorGo.h ========================== * -- tpr -- * CREATE -- 2019.12.08 * MODIFY -- * ---------------------------------------------------------- */ #ifndef TPR_GO_FLOOR_GO_H #define TPR_GO_FLOOR_GO_H //-------------------- Engine --------------------// #include "GameObj.h" #include "DyParam.h" namespace gameObjs{//------------- namespace gameObjs ---------------- class FloorGo{ public: static void init(GameObj &goRef_, const DyParam &dyParams_ ); private: //--- callback ---// static void OnRenderUpdate( GameObj &goRef_ ); static void OnActionSwitch( GameObj &goRef_, ActionSwitchType type_ ); }; }//------------- namespace gameObjs: end ---------------- #endif
turesnake/tprPixelGames
src/Engine/ecoSys/DensityPool.h
/* * ======================= DensityPool.h ======================= * -- tpr -- * CREATE -- 2019.10.07 * MODIFY -- * ---------------------------------------------------------- */ #ifndef TPR_DENSITY_POOL_H #define TPR_DENSITY_POOL_H #include "pch.h" //-------------------- Engine --------------------// #include "GoSpecData.h" #include "random.h" #include "blueprintId.h" //--- need ---// class FieldDistributePlan; class DensityPool{ public: DensityPool()=default; inline void set_applyPercent( double percent_ )noexcept{ this->applyPercent = percent_; } inline void insert_2_yardBlueprintIds( blueprint::yardBlueprintId_t yardId_, size_t num_ )noexcept{ this->yardBlueprintIds.insert( this->yardBlueprintIds.end(), num_, yardId_ ); } inline void shuffle( std::default_random_engine &engine_ )noexcept{ std::shuffle( this->yardBlueprintIds.begin(), this->yardBlueprintIds.end(), engine_ ); } // param: randUVal_ [0, 9999] inline bool isNeed2Apply( size_t randUVal_ )const noexcept{ if( this->yardBlueprintIds.empty() ){ return false; } if( is_closeEnough<double>(this->applyPercent, 0.0, 0.001) ){ return false; } double randV = static_cast<double>(randUVal_) * 0.3717 + 313.717; double fract = randV - floor(randV); return ((fract < this->applyPercent) ? true : false); } inline blueprint::yardBlueprintId_t apply_a_yardBlueprintId( size_t uWeight_ )const noexcept{ //-- 应该已经被 isNeed2Apply 过滤掉了 tprAssert( !this->yardBlueprintIds.empty() ); size_t idx = (uWeight_ + 17595441) % this->yardBlueprintIds.size(); return this->yardBlueprintIds.at( idx ); } private: double applyPercent {}; //- [0.0, 1.0] std::vector<blueprint::yardBlueprintId_t> yardBlueprintIds {}; }; #endif
turesnake/tprPixelGames
src/Engine/resource/esrc_shader.h
/* * ========================= esrc_shader.h ========================== * -- tpr -- * CREATE -- 2019.04.19 * MODIFY -- * ---------------------------------------------------------- */ #ifndef TPR_ESRC_SHADER_H #define TPR_ESRC_SHADER_H //-------------------- Engine --------------------// #include "ShaderProgram.h" #include "ShaderType.h" namespace esrc {//------------------ namespace: esrc -------------------------// void init_shaders(); ShaderProgram &get_shaderRef( ShaderType type_ )noexcept; ShaderProgram *get_shaderPtr( ShaderType type_ )noexcept; }//---------------------- namespace: esrc -------------------------// #endif
turesnake/tprPixelGames
src/Engine/multiThread/chunkCreate/Job_MapEnt.h
<reponame>turesnake/tprPixelGames /* * ========================== Job_MapEnt.h ======================= * -- tpr -- * CREATE -- 2019.09.26 * MODIFY -- * ---------------------------------------------------------- */ #ifndef TPR_JOB_MAP_ENT_H #define TPR_JOB_MAP_ENT_H #include "pch.h" //-------------------- Engine --------------------// #include "sectionKey.h" #include "chunkKey.h" #include "fieldKey.h" #include "colorTableId.h" #include "Density.h" #include "MapAltitude.h" #include "GoSpecData.h" //-------------------- Script --------------------// #include "Script/gameObjs/bioSoup/BioSoupState.h" // need: class MemMapEnt; // tmp data. created in job threads class Job_MapEnt{ public: explicit Job_MapEnt( IntVec2 mpos_ ) { this->init( mpos_ );// 并不完整,还有一部分在 calc_job_chunk() 中完成 } //---------- init ----------// inline void init_ecoObjKey( sectionKey_t key_ )noexcept{ tprAssert( !this->ecoObjKey.has_value() ); this->ecoObjKey = {key_}; } inline void init_colorTableId( colorTableId_t id_ )noexcept{ tprAssert( !this->colorTableId.has_value() ); this->colorTableId = {id_}; } inline void init_density( Density density_ )noexcept{ tprAssert( !this->density.has_value() ); this->density = {density_}; } inline void init_isEcoBorder( bool b_ )noexcept{ tprAssert( !this->isEcoBorder.has_value() ); this->isEcoBorder = {b_}; } //---------- get ----------// inline IntVec2 get_mpos()const noexcept{ tprAssert( this->mpos.has_value() ); return this->mpos.value(); } inline chunkKey_t get_chunkKey()const noexcept{ tprAssert( this->chunkKey.has_value() ); return this->chunkKey.value(); } inline sectionKey_t get_ecoObjKey()const noexcept{ tprAssert( this->ecoObjKey.has_value() ); return this->ecoObjKey.value(); } inline colorTableId_t get_colorTableId()const noexcept{ tprAssert( this->colorTableId.has_value() ); return this->colorTableId.value(); } inline Density get_density()const noexcept{ tprAssert( this->density.has_value() ); return this->density.value(); } inline MapAltitude get_alti()const noexcept{ tprAssert( this->alti.has_value() ); return this->alti.value(); } inline gameObjs::bioSoup::State get_bioSoupState()const noexcept{ tprAssert( this->bioSoupState.has_value() ); return this->bioSoupState.value(); } inline size_t get_uWeight()const noexcept{ tprAssert( this->uWeight.has_value() ); return this->uWeight.value(); } inline bool get_isEcoBorder()const noexcept{ tprAssert( this->isEcoBorder.has_value() ); return this->isEcoBorder.value(); } private: void init( IntVec2 mpos_ )noexcept; //====== vals ======// // 确保每个数据,只被 init一次 std::optional<IntVec2> mpos {std::nullopt}; std::optional<chunkKey_t> chunkKey {std::nullopt}; std::optional<sectionKey_t> ecoObjKey {std::nullopt}; std::optional<colorTableId_t> colorTableId {std::nullopt}; // same as ecoObj.colorTableId std::optional<Density> density {std::nullopt}; std::optional<MapAltitude> alti {std::nullopt}; std::optional<gameObjs::bioSoup::State> bioSoupState {std::nullopt}; std::optional<size_t> uWeight {std::nullopt}; // [0, 9999] std::optional<bool> isEcoBorder {std::nullopt}; //- 是否为 eco边缘go default:false // 在未来,将被拓展为 一个 具体的数字,表示自己离 border 的距离(mapents)... }; #endif
turesnake/tprPixelGames
src/Engine/color/ColorTable.h
/* * ======================= ColorTable.h ========================== * -- tpr -- * CREATE -- 2019.09.21 * MODIFY -- * ---------------------------------------------------------- * 数组色卡,管理 游戏世界 中的所有颜色 * * * 这部分功能,目前被削弱了,很少被用上 ... * * * --------- */ #ifndef TPR_COLOR_TABLE_H #define TPR_COLOR_TABLE_H #include "pch.h" //-------------------- CPP --------------------// #include <utility> // pair #include <cstdint> //-------------------- Engine --------------------// #include "FloatVec.h" #include "ID_Manager.h" #include "colorTableId.h" #include "EcoSysPlanType.h" //-- colorTable.data 中实际存储的 entName -- inline std::unordered_map<std::string, size_t> colorTableEntNames{ //-- 基础色 -- { "base_0", 0 }, { "base_1", 1 }, { "base_2", 2 }, { "base_3", 3 }, { "base_4", 4 }, { "base_5", 5 }, { "base_6", 6 }, { "base_7", 7 }, //-- 地面色 -- { "ground", 8 }, // more ... }; class ColorTable{ public: ColorTable() { this->data.resize(colorTableEntNames.size()); } template< typename PtrType > inline PtrType get_dataPtr()const noexcept{ return static_cast<PtrType>( &(this->data.at(0)) ); } inline std::vector<FloatVec4> &getnc_dataRef()noexcept{ return this->data; } inline const std::vector<FloatVec4> &get_dataRef()const noexcept{ return this->data; } inline void insert_a_color(const std::string &name_, const FloatVec4 &color_ )noexcept{ tprAssert( colorTableEntNames.find(name_) != colorTableEntNames.end() ); this->data.at(colorTableEntNames.at(name_)) = color_; auto [insertIt, insertBool] = this->isSets.insert( name_ ); tprAssert( insertBool ); } inline void final_check()const noexcept{ for( const auto &[iName, iVal] : colorTableEntNames ){ tprAssert( this->isSets.find(iName) != this->isSets.end() ); } } //- Must called in init -- inline void init_all_color_white()noexcept{ tprAssert( this->isSets.empty() ); for( const auto &[iName, iVal] : colorTableEntNames ){ auto [insertIt, insertBool] = this->isSets.insert( iName ); tprAssert( insertBool ); //--- this->data.at(iVal) = { 1.0, 1.0, 1.0, 1.0 };//- white } } inline const FloatVec4 &get_groundColor()const noexcept{ return this->data.at(colorTableEntNames.at("ground")); } //======== static ========// inline static size_t get_dataSize()noexcept{ return (colorTableEntNames.size()*sizeof(FloatVec4)); } static ID_Manager id_manager; private: std::vector<FloatVec4> data {}; // colorTable std::unordered_set<std::string> isSets {}; // just used in json-read }; class ColorTableSet{ public: ColorTableSet()=default; inline std::pair<colorTableId_t, ColorTable*> apply_new_colorTable( const std::string &name_ )noexcept{ colorTableId_t id = ColorTable::id_manager.apply_a_u32_id();// start from 1 //--- this->name_ids.insert({ name_, id }); auto [insertIt, insertBool] = this->colorTableUPtrs.emplace( id, std::make_unique<ColorTable>() ); tprAssert( insertBool ); //--- return { id, insertIt->second.get() }; } inline void final_check()noexcept{ tprAssert( this->isFindIn_name_ids("origin") );// Must Have!!! //--- ground color table ---// //-- fst ent will be skip -- this->groundColorTable.resize( this->colorTableUPtrs.size() + 1 ); for( const auto &[iId, iUPtr] : this->colorTableUPtrs ){ this->groundColorTable.at(iId) = iUPtr->get_groundColor(); } //--- this->debug(); } inline colorTableId_t get_colorTableId( const std::string &colorTableName_ )const noexcept{ tprAssert( this->isFindIn_name_ids(colorTableName_) ); return this->name_ids.at(colorTableName_); } inline const std::unordered_map<std::string, colorTableId_t> & get_name_idsRef()const noexcept{ return this->name_ids; } inline const ColorTable &get_colorTableRef( colorTableId_t id_ )const noexcept{ tprAssert( this->colorTableUPtrs.find(id_) != this->colorTableUPtrs.end() ); return *(this->colorTableUPtrs.at(id_)); } inline const ColorTable *get_colorTablePtr( colorTableId_t id_ )const noexcept{ tprAssert( this->colorTableUPtrs.find(id_) != this->colorTableUPtrs.end() ); return this->colorTableUPtrs.at(id_).get(); } //----- groundColor -----// template< typename PtrType > inline PtrType get_groundColor_dataPtr()const noexcept{ return static_cast<PtrType>( &(this->groundColorTable.at(0)) ); } inline size_t get_groundColor_dataSize()const noexcept{ return (this->groundColorTable.size() * sizeof(FloatVec4)); } //--- JUST used in TEST !!!!!!! inline const std::vector<FloatVec4> &get_groundColorTable_test()const noexcept{ return this->groundColorTable; } inline void insert_2_ecoSysPlanTypes( colorTableId_t id_, EcoSysPlanType type_ )noexcept{ tprAssert( (type_!=EcoSysPlanType::BegIdx) && (type_!=EcoSysPlanType::EndIdx) ); auto [insertIt, insertBool] = this->ecoSysPlanTypes.emplace( id_, type_ ); tprAssert( insertBool ); } inline EcoSysPlanType get_ecoSysPlanType( colorTableId_t id_ )const noexcept{ tprAssert( this->ecoSysPlanTypes.find(id_) != this->ecoSysPlanTypes.end() ); return this->ecoSysPlanTypes.at(id_); } private: inline bool isFindIn_name_ids( const std::string name_ )const noexcept{ return (this->name_ids.find(name_) != this->name_ids.end()); } void debug()noexcept; //----- vals -----// std::unordered_map<std::string, colorTableId_t> name_ids {}; std::unordered_map<colorTableId_t, std::unique_ptr<ColorTable>> colorTableUPtrs {}; std::vector<FloatVec4> groundColorTable {}; // idx by colorTableId // 0: empty, skip it !!! // 1: origin colorTable // 2~n: ent std::unordered_map<colorTableId_t, EcoSysPlanType> ecoSysPlanTypes {}; }; //-- 维护一个动态的 ColorTable 实例,表示当前帧的 世界颜色 -- // 可以让它趋近于某种目标色 // 通常是 playergo 所在dpos 的 eco 的色表(或者正在过度向这个色表的中间色) // class CurrentColorTable{ public: CurrentColorTable() { this->data.init_all_color_white(); } inline void rebind_target( const ColorTable *targetPtr_ )noexcept{ if( this->targetColorTablePtr != targetPtr_ ){ this->targetColorTablePtr = targetPtr_; this->isWorking = true; } } void update()noexcept; inline const ColorTable &get_colorTableRef()const noexcept{ return this->data; } inline bool get_isWorking()const noexcept{ return this->isWorking; } private: ColorTable data {}; const ColorTable *targetColorTablePtr {nullptr}; //===== flags =====// bool isWorking {true}; // 本色是否正在趋近于 目标色 }; #endif
turesnake/tprPixelGames
src/Engine/resource/esrc_player.h
<gh_stars>100-1000 /* * ======================= esrc_player.h ========================== * -- tpr -- * CREATE -- 2019.04.19 * MODIFY -- * ---------------------------------------------------------- */ #ifndef TPR_ESRC_PLAYER_H #define TPR_ESRC_PLAYER_H //-------------------- Engine --------------------// #include "Player.h" namespace esrc {//------------------ namespace: esrc -------------------------// void init_player(); Player &get_player(); }//---------------------- namespace: esrc -------------------------// #endif
turesnake/tprPixelGames
deps/tprInUnix/wrapUnix.h
<filename>deps/tprInUnix/wrapUnix.h<gh_stars>100-1000 /* * ========================= wrapUnix.h ========================== * -- tpr -- * CREATE -- 2018.09.11 * MODIFY -- * ---------------------------------------------------------- * 包裹函数 * ---------------------------- */ #ifndef TPR_WRAP_UNIX_H_ #define TPR_WRAP_UNIX_H_ //#include <sys/socket.h> //- socklen_t, sockaddr //#include <netinet/in.h> //- sockaddr_in #include <fcntl.h> //- mode_t, O_RDONLY, O_WRONLY #include <string> namespace tprUnix {//--------------- namespace: tprUnix -------------------// //========================== wrap_unix.cpp ===============================// int Open( const char *path_, int oflag_, mode_t mode_, const std::string &err_info_ ); void Mkdir( const char *path_, mode_t mode_, const std::string &err_info_ ); void Mkdirat( int fd_, const char *path_, mode_t mode_, const std::string &err_info_ ); void Close( int fd_, const std::string &err_info_ ); off_t Lseek( int fd_, off_t offset_, int whence_, const std::string &err_info_); void Fseeko( FILE *fp_, off_t offset_, int whence_, const std::string &err_info_); //off_t Ftello( FILE *fp_, const std::string &err_info_ ); /* pid_t Fork( const std::string &err_info_ ); void Wait( int *_status, pid_t _pid_target, const std::string &err_info_ ); int Select( int _maxfdp1, fd_set *_readset, fd_set *_writeset, fd_set *_exceptset, struct timeval *_timeout, const std::string &err_info_ ); */ ssize_t Read( int fd_, void *buf_, size_t nbytes_, const std::string &err_info_ ); void Write( int fd_, const void *buf_, size_t nbytes_, const std::string &err_info_ ); std::string Getenv( const char *name_, const std::string &err_info_ ); //========================== wrap_socket.cpp ===============================// /* int Socket( int _family, int type_, int _protocol, const std::string &err_info_ ); int Accept( int _sockfd, struct sockaddr *_cliaddr, socklen_t *_addrlen, const std::string &err_info_ ); void Bind( int _sockfd, const struct sockaddr *_addr, socklen_t _len, const std::string &err_info_ ); void Connect( int _sockfd, const struct sockaddr *_servaddr, socklen_t _addrlen, const std::string &err_info_ ); void Listen( int _sockfd, int _backlog, const std::string &err_info_ ); const char* Inet_ntop( int _family, const void* _addrptr, char* _strptr, socklen_t _size, const std::string &err_info_ ); void Inet_pton( int _family, const char* _strptr, void* _addrptr, const std::string &err_info_ ); void Shutdown( int _sockfd, int _howto, const std::string &err_info_ ); */ }//------------------- namespace: tprUnix ------------------------// #endif
turesnake/tprPixelGames
src/Engine/dataBase/wrapSqlite3.h
<reponame>turesnake/tprPixelGames<filename>src/Engine/dataBase/wrapSqlite3.h /* * ====================== wrapSqlite3.h ======================= * -- tpr -- * CREATE -- 2019.04.22 * MODIFY -- * ---------------------------------------------------------- * wrap funcs of sqlite3 * ---------------------------- */ #ifndef TPR_WRAP_SQLITE3_H #define TPR_WRAP_SQLITE3_H //-------------------- CPP --------------------// #include <string> //-------------------- Libs --------------------// #include "tprAssert.h" #include "sqlite3.h" #include "tprDebug.h" /* =========================================================== * handle_sqlite_err_inn * ----------------------------------------------------------- * -- 版本1,更加精细的出错信息 * -- 版本2,仅仅翻译 ERROR CODE 名称 */ inline void handle_sqlite_err_inn( sqlite3 *db_, int rc_, const std::string &funcName_ ){ tprAssert( rc_ != SQLITE_OK ); tprDebug::console( "ERROR: {0}: \n{1}", funcName_, sqlite3_errmsg( db_ ) ); sqlite3_close( db_ ); //- better tprAssert(0); } inline void handle_sqlite_err_without_db_inn( int rc_, const std::string &funcName_ ){ tprAssert( rc_ != SQLITE_OK ); tprDebug::console( "ERROR_CODE: {0}: \n{1}", funcName_, sqlite3_errstr( rc_ ) ); tprAssert(0); } /* =============================================== * config : singleThread * ----------------------------------------------- * -- 废弃,改为从 编译器设置 */ inline void w_sqlite3_config_singleThread(){ int rc = sqlite3_config( SQLITE_CONFIG_SINGLETHREAD ); if( rc != SQLITE_OK ){ handle_sqlite_err_without_db_inn( rc, "sqlite3_config():single_thread" ); } } /* =============================================== * open * ----------------------------------------------- */ inline void w_sqlite3_open( const char *filename_, /* Database filename (UTF-8) */ sqlite3 **ppDb_ /* OUT: SQLite db handle */ ){ int rc = sqlite3_open(filename_, ppDb_); if( rc != SQLITE_OK ){ handle_sqlite_err_inn( *ppDb_, rc, "sqlite3_open()" ); } } /* =============================================== * exec * ----------------------------------------------- */ inline void w_sqlite3_exec( sqlite3* db_, /* An open database */ const char *sql_, /* SQL to be evaluated */ int (*callback_)(void*,int,char**,char**), /* Callback function */ void *fstArg_, /* 1st argument to callback */ char **errmsg_ /* Error msg written here */ ){ int rc = sqlite3_exec( db_, sql_, callback_, fstArg_, errmsg_ ); if( rc != SQLITE_OK ){ handle_sqlite_err_inn( db_, rc, "sqlite3_exec()" ); } } /* =============================================== * prepare * ----------------------------------------------- */ inline void w_sqlite3_prepare_v2( sqlite3 *db_, /* Database handle */ const char *zSql_, /* SQL statement, UTF-8 encoded */ int nByte_, /* Maximum length of zSql in bytes. */ sqlite3_stmt **ppStmt_, /* OUT: Statement handle */ const char **pzTail_ /* OUT: Pointer to unused portion of zSql */ ){ int rc = sqlite3_prepare_v2( db_, zSql_, nByte_, ppStmt_, pzTail_ ); if( rc != SQLITE_OK ){ handle_sqlite_err_inn( db_, rc, "sqlite3_prepare_v2()" ); } } /* =============================================== * reset * ----------------------------------------------- */ inline void w_sqlite3_reset( sqlite3 *db_, sqlite3_stmt *pStmt_ ){ int rc = sqlite3_reset( pStmt_ ); if( rc != SQLITE_OK ){ handle_sqlite_err_inn( db_, rc, "sqlite3_reset()" ); } } /* =============================================== * step * ----------------------------------------------- */ //-- 一个不全面的 wrap,仅适用于 部分场合 -- inline void w_sqlite3_step( sqlite3 *db_, sqlite3_stmt *pStmt_, int resultCord_){ int rc = sqlite3_step( pStmt_ ); if( rc != resultCord_ ){ handle_sqlite_err_inn( db_, rc, "sqlite3_step()" ); } } /* =============================================== * finalize * ----------------------------------------------- */ inline void w_sqlite3_finalize( sqlite3 *db_, sqlite3_stmt *pStmt_ ){ int rc = sqlite3_finalize( pStmt_ ); if( rc != SQLITE_OK ){ handle_sqlite_err_inn( db_, rc, "sqlite3_finalize()" ); } } /* =============================================== * bind * ----------------------------------------------- */ inline void w_sqlite3_bind_blob( sqlite3 *db_, sqlite3_stmt *pStmt_, int idx_, const void *val_, int valSize_, void(*callback_)(void*)){ int rc = sqlite3_bind_blob( pStmt_, idx_, val_, valSize_, callback_ ); if( rc != SQLITE_OK ){ handle_sqlite_err_inn( db_, rc, "sqlite3_bind_blob()" ); } } //-- 暂不使用 blob64 -- //int sqlite3_bind_blob64(sqlite3_stmt *pStmt_, int idx_, const void *val_, sqlite3_uint64 valSize_, void(*callback_)(void*)); inline void w_sqlite3_bind_double( sqlite3 *db_, sqlite3_stmt *pStmt_, int idx_, double val_){ int rc = sqlite3_bind_double( pStmt_, idx_, val_); if( rc != SQLITE_OK ){ handle_sqlite_err_inn( db_, rc, "sqlite3_bind_double()" ); } } inline void w_sqlite3_bind_int( sqlite3 *db_, sqlite3_stmt *pStmt_, int idx_, int val_){ int rc = sqlite3_bind_int( pStmt_, idx_, val_); if( rc != SQLITE_OK ){ handle_sqlite_err_inn( db_, rc, "sqlite3_bind_int()" ); } } inline void w_sqlite3_bind_int64( sqlite3 *db_, sqlite3_stmt *pStmt_, int idx_, sqlite3_int64 val_){ int rc = sqlite3_bind_int64( pStmt_, idx_, val_); if( rc != SQLITE_OK ){ handle_sqlite_err_inn( db_, rc, "sqlite3_bind_int64()" ); } } inline void w_sqlite3_bind_null( sqlite3 *db_, sqlite3_stmt *pStmt_, int idx_){ int rc = sqlite3_bind_null( pStmt_, idx_); if( rc != SQLITE_OK ){ handle_sqlite_err_inn( db_, rc, "sqlite3_bind_null()" ); } } inline void w_sqlite3_bind_text( sqlite3 *db_, sqlite3_stmt *pStmt_, int idx_, const char *val_, int valSize_, void(*callback_)(void*)){ int rc = sqlite3_bind_text( pStmt_, idx_, val_, valSize_, callback_ ); if( rc != SQLITE_OK ){ handle_sqlite_err_inn( db_, rc, "sqlite3_bind_text()" ); } } //-- 暂不使用 text16 -- //int sqlite3_bind_text16(sqlite3_stmt *pStmt_, int idx_, const void *val_, int valSize_, void(*callback_)(void*)); //-- 暂不使用 text64 -- //int sqlite3_bind_text64(sqlite3_stmt *pStmt_, int idx_, const char *val_, sqlite3_uint64 valSize_, void(*callback_)(void*), unsigned char _encoding); //-- 暂不使用 sqlite3_value -- //int sqlite3_bind_value(sqlite3_stmt *pStmt_, int idx_, const sqlite3_value *val_); //-- 暂不使用 pointer -- //int sqlite3_bind_pointer( sqlite3_stmt *pStmt_, int idx_, void *val_, const char *type_, void(*callback_)(void*) ); inline void w_sqlite3_bind_zeroblob( sqlite3 *db_, sqlite3_stmt *pStmt_, int idx_, int valSize_){ int rc = sqlite3_bind_zeroblob( pStmt_, idx_, valSize_); if( rc != SQLITE_OK ){ handle_sqlite_err_inn( db_, rc, "sqlite3_bind_zeroblob()" ); } } //-- 暂不使用 zeroblob64 -- //int sqlite3_bind_zeroblob64(sqlite3_stmt *pStmt_, int idx_, sqlite3_uint64 valSize_); /* =============================================== * paramName -> paramIdx * ----------------------------------------------- */ inline int w_sqlite3_bind_parameter_index( sqlite3_stmt *pStmt_, const char *zName_){ int retIdx = sqlite3_bind_parameter_index( pStmt_, zName_); if( retIdx == 0 ){ tprDebug::console( "cant find parameter: {}", zName_ ); tprAssert(0); } return retIdx; } /* =============================================== * column * ----------------------------------------------- */ //-- 暂不需要 wrap -- #endif
turesnake/tprPixelGames
src/Engine/animFrameSet/AnimSubspecies.h
/* * ===================== AnimSubspecies.h ========================== * -- tpr -- * CREATE -- 2019.09.09 * MODIFY -- * ---------------------------------------------------------- */ #ifndef TPR_ANIM_SUB_SPECIES_H #define TPR_ANIM_SUB_SPECIES_H #include "pch.h" //-------------------- CPP --------------------// #include <algorithm> //-------------------- Engine --------------------// #include "ID_Manager.h" #include "AnimAction.h" #include "animSubspeciesId.h" #include "AnimActionEName.h" #include "NineDirection.h" #include "BrokenLvl.h" //-- 亚种 -- // 保存并管理一组 animAction 实例 class AnimSubspecies{ public: AnimSubspecies()=default; inline AnimAction &insert_new_animAction( NineDirection dir_, BrokenLvl brokenLvl_, AnimActionEName actionEName_ )noexcept{ // if target key is existed, nothing will happen this->animActions.insert({ dir_, std::unordered_map<BrokenLvl, std::unordered_map<AnimActionEName, std::unique_ptr<AnimAction>>>{} }); // maybe this->animActions.at(dir_).insert({ brokenLvl_, std::unordered_map<AnimActionEName, std::unique_ptr<AnimAction>>{} }); // maybe auto &container = this->animActions.at(dir_).at(brokenLvl_); auto [insertIt, insertBool] = container.emplace( actionEName_, std::make_unique<AnimAction>() ); tprAssert( insertBool ); // Must //--- // if target key is existed, nothing will happen this->actionsDirs.insert({ actionEName_, std::unordered_set<NineDirection>{} }); //- maybe this->actionsDirs.at(actionEName_).insert( dir_ ); //- maybe //--- return *(container.at(actionEName_).get()); } // 三层参数都有可能出错,用 opt 来管理。让外部处理 inline std::optional<AnimAction*> get_animActionPtr( NineDirection dir_, BrokenLvl brokenLvl_, AnimActionEName actionEName_ )const noexcept{ if( this->animActions.find(dir_) == this->animActions.end() ){ return std::nullopt; } auto &container_1 = this->animActions.at(dir_); //--- if( container_1.find(brokenLvl_) == container_1.end() ){ return std::nullopt; } auto &container_2 = container_1.at(brokenLvl_); //--- if( container_2.find(actionEName_) == container_2.end() ){ return std::nullopt; } return { container_2.at(actionEName_).get() }; } inline const std::unordered_set<NineDirection> &get_actionDirs( AnimActionEName actionEName_ )const noexcept{ tprAssert( this->actionsDirs.find(actionEName_) != this->actionsDirs.end() ); return this->actionsDirs.at(actionEName_); } inline static animSubspeciesId_t apply_new_animSubspeciesId()noexcept{ animSubspeciesId_t id = AnimSubspecies::id_manager.apply_a_u32_id(); if( is_empty_animSubspeciesId(id) ){ id = AnimSubspecies::id_manager.apply_a_u32_id(); // do apply again } return id; } private: //-- 丑陋的实现,3层嵌套容器 std::unordered_map<NineDirection, std::unordered_map<BrokenLvl, std::unordered_map<AnimActionEName, std::unique_ptr<AnimAction>>>> animActions {}; std::unordered_map<AnimActionEName, std::unordered_set<NineDirection>> actionsDirs {}; //======== static ========// static ID_Manager id_manager; //- 负责生产 id }; //-- 一组亚种ids,相互间,拥有相同的 animLabel,不同的序号idx -- class AnimSubspeciesSquad{ public: AnimSubspeciesSquad() { this->subIdxs.reserve(4); this->subspeciesIds.reserve(4); } inline animSubspeciesId_t find_or_create( size_t subIdx_ )noexcept{ if( this->subspeciesIds.find(subIdx_) == this->subspeciesIds.end() ){ animSubspeciesId_t id = AnimSubspecies::apply_new_animSubspeciesId(); this->subspeciesIds.insert({ subIdx_, id }); this->subIdxs.push_back( subIdx_ ); return id; }else{ return this->subspeciesIds.at(subIdx_); } } inline animSubspeciesId_t apply_a_random_animSubspeciesId( size_t uWeight_ )const noexcept{ if( this->subspeciesIds.size() == 1 ){ return this->subspeciesIds.begin()->second; //- only one } size_t i = (uWeight_ + 366179) % this->subIdxs.size(); return this->subspeciesIds.at( this->subIdxs.at(i) ); } inline void check()const noexcept{ tprAssert( !this->subIdxs.empty() ); tprAssert( !this->subspeciesIds.empty() ); } private: std::vector<size_t> subIdxs {}; std::unordered_map<size_t,animSubspeciesId_t> subspeciesIds {}; }; //-- 通过 animLabel 来管理 所有亚种 -- class AnimSubspeciesGroup{ public: AnimSubspeciesGroup() { this->labels.reserve(4); this->subSquads.reserve(4); } //-- 空值需要传入 AnimLabel::Default inline animSubspeciesId_t find_or_create_a_animSubspeciesId( const std::string & label_, size_t subIdx_ )noexcept{ if( this->subSquads.find(label_) == this->subSquads.end() ){ auto [insertIt, insertBool] = this->subSquads.emplace( label_, AnimSubspeciesSquad{} ); tprAssert( insertBool ); //--- this->labels.push_back( label_ ); } return this->subSquads.at(label_).find_or_create( subIdx_ ); } // param: uWeight_ [0, 9999] inline animSubspeciesId_t apply_a_random_animSubspeciesId( const std::string & label_, size_t uWeight_ )noexcept{ if( label_ == "" ){ size_t idx = (uWeight_ + 735157) % this->labels.size(); const std::string &tmpLabel = this->labels.at(idx); return this->subSquads.at(tmpLabel).apply_a_random_animSubspeciesId( uWeight_ ); }else{ tprAssert( this->subSquads.find(label_) != this->subSquads.end() ); return this->subSquads.at(label_).apply_a_random_animSubspeciesId( uWeight_ ); } } inline void check()noexcept{ tprAssert( !this->labels.empty() ); //--- subSquads --- tprAssert( !this->subSquads.empty() ); for( const auto &i : this->subSquads ){ i.second.check(); } } private: std::vector<std::string> labels {}; // 所有被登记的 labels. ( "" == default ) std::unordered_map<std::string, AnimSubspeciesSquad> subSquads {}; }; #endif
turesnake/tprPixelGames
src/Engine/tprDebug/tprDebug.h
<gh_stars>100-1000 /* * ========================= tprDebug.h ========================== * -- tpr -- * CREATE -- 2019.01.05 * MODIFY -- * ---------------------------------------------------------- * MOST POOR DEBUG SYSTEM * ---------------------------- */ #ifndef TPR_DEBUG_H #define TPR_DEBUG_H #include <utility> #include <string> #include "fmt/format.h" namespace tprDebug {//---------- namespace: tprDebug --------------// // 简单地打印一段 字符串到 console // 推荐使用 fmt 拼接 void tmp_console_inn( const std::string &str_ ); // 简单的套娃 template < typename S, typename... Args > void console(const S& format_str, Args&&... args) { auto str = fmt::format( format_str, std::forward<Args>(args)... ); tmp_console_inn( str ); } }//-------------------- namespace: tprDebug end --------------// #endif
turesnake/tprPixelGames
src/Script/gameObjs/bioSoup/BioSoupDataForCreate.h
/* * ================== BioSoupDataForCreate.h ======================= * -- tpr -- * CREATE -- 2020.03.02 * MODIFY -- * ---------------------------------------------------------- */ #ifndef TPR_BIO_SOUP_DATA_FOR_CREATE_H #define TPR_BIO_SOUP_DATA_FOR_CREATE_H //-------------------- Engine --------------------// #include "MapAltitude.h" //-------------------- Script --------------------// #include "Script/gameObjs/bioSoup/BioSoupState.h" namespace gameObjs::bioSoup {//------------- namespace gameObjs::bioSoup ---------------- // used in goDataForCreate class DataForCreate{ public: DataForCreate()=default; //----- vals -----// State bioSoupState {}; MapAltitude mapEntAlti {}; }; }//------------- namespace gameObjs::bioSoup: end ---------------- #endif
turesnake/tprPixelGames
src/Engine/resource/esrc_chunkMemState.h
<filename>src/Engine/resource/esrc_chunkMemState.h<gh_stars>100-1000 /* * ================== esrc_chunkMemState.h ========================== * -- tpr -- * CREATE -- 2019.07.10 * MODIFY -- * ---------------------------------------------------------- * only included by esrc_chunk.h */ #ifndef TPR_ESRC_CHUNK_MEM_STATE_H #define TPR_ESRC_CHUNK_MEM_STATE_H //-------------------- CPP --------------------// #include <utility> #include <optional> //-------------------- Engine --------------------// #include "Chunk.h" #include "chunkKey.h" #include "IntVec.h" #include "ChunkMemState.h" namespace esrc {//------------------ namespace: esrc -------------------------// void init_chunkMemStates()noexcept; void chunkMemState_debug( chunkKey_t key_, const std::string &str_ ); // debug tmp //-- chunkKeys -- void insert_chunkKey_2_waitForCreate( chunkKey_t chunkKey_ )noexcept; void insert_chunkKey_2_onCreating( chunkKey_t chunkKey_ )noexcept; const std::unordered_set<chunkKey_t> &get_chunkKeys_waitForCreate()noexcept; void move_chunkKey_from_waitForCreate_2_onCreating( chunkKey_t chunkKey_ )noexcept; void move_chunkKey_from_onCreating_2_active( chunkKey_t chunkKey_ )noexcept; void move_chunkKey_from_active_2_waitForRelease( chunkKey_t chunkKey_ )noexcept; std::optional<chunkKey_t> pop_front_from_WaitForRelease_and_move_2_onReleasing()noexcept; ChunkMemState get_chunkMemState( chunkKey_t chunkKey_ )noexcept; }//---------------------- namespace: esrc -------------------------// #endif
turesnake/tprPixelGames
src/Engine/affect/Affect.h
<gh_stars>100-1000 /* * ========================== Affect.h ========================== * -- tpr -- * CREATE -- 2019.02.03 * MODIFY -- * ---------------------------------------------------------- * 一个go实例 通常会绑定两个 Affect实例: * - 碰撞检测时,作为 被动go 触发的 affect * - 碰撞检测时,作为 主动go 触发的 affect * ---------------------------- */ #ifndef TPR_AFFECT_H #define TPR_AFFECT_H class Affect{ public: }; #endif
turesnake/tprPixelGames
src/Engine/script/ScriptBuf.h
<filename>src/Engine/script/ScriptBuf.h /* * ========================= ScriptBuf.h ========================== * -- tpr -- * CREATE -- 2019.01.01 * MODIFY -- * ---------------------------------------------------------- * Engine-Script: params/retVal buffer * ----- * * * * 目前,此装置未被使用..... * * * * * ---------------------------- */ #ifndef TPR_SCRIPT_BUF_H #define TPR_SCRIPT_BUF_H //-------------------- C --------------------// #include <cstring> //- memcpy //-------------------- CPP --------------------// #include <vector> #include <string> //------------------- Engine --------------------// #include "tprAssert.h" //--- 一个更加强大,专业的 引擎-脚本 参数/返回值 传递工具 --- // 每种类型拥有 独立的容器 和 状态flag检测 // 允许向 同一个容器 多次 push, 而不做任何 pop 操作 // 但是如果一个 容器未被 push,就调用 pop 操作 将报错 // pop 只能执行一次。 之后容器中的数据就被 “销毁” class ScriptBuf{ public: //============== bool ==============// inline void push_bool( bool b_ )noexcept{ boolval = b_; is_boolval_push = true; } inline bool pop_bool()noexcept{ tprAssert( is_boolval_push == true ); is_boolval_push = false; return boolval; } //============== int ==============// inline void push_int( int i_ )noexcept{ i32val = i_; is_i32val_push = true; } inline int pop_int()noexcept{ tprAssert( is_i32val_push == true ); is_i32val_push = false; return i32val; } //============== uint64_t ==============// inline void push_u64( uint64_t u_ )noexcept{ u64val = u_; is_u64val_push = true; } inline uint64_t pop_u64()noexcept{ tprAssert( is_u64val_push == true ); is_u64val_push = false; return u64val; } //============== string ==============// inline void push_str( std::string str_ )noexcept{ str = str_; is_str_push = true; } inline std::string pop_str()noexcept{ tprAssert( is_str_push == true ); is_str_push = false; return str; //- copy } //============== binary ==============// inline void push_binary( void *buf_, int len_ )noexcept{ binary.resize(len_); memcpy( (void*)&(binary.at(0)), buf_, (size_t)len_ ); is_binary_push = true; } inline void pop_binary( void *buf_, int len_ )noexcept{ //- 非常严格,buf长度不匹配也将 报错 tprAssert( is_binary_push == true ); is_binary_push = false; tprAssert( binary.size() == len_ ); memcpy( buf_, (void*)&(binary.at(0)), (size_t)len_ ); binary.clear(); } private: //------ val container --- bool boolval {}; int i32val {}; uint64_t u64val {}; std::vector<uint8_t> binary {}; std::string str {}; //======== flags ========// bool is_boolval_push {false}; bool is_i32val_push {false}; bool is_u64val_push {false}; bool is_str_push {false}; bool is_binary_push {false}; }; //-- 本类唯一的实例,全局 ---- inline ScriptBuf scriptBuf {}; #endif
turesnake/tprPixelGames
src/Engine/tools/U8Vec.h
<reponame>turesnake/tprPixelGames<gh_stars>100-1000 /* * ========================= U8Vec.h ========================== * -- tpr -- * CREATE -- 2019.03.10 * MODIFY -- * ---------------------------------------------------------- * 以像素为单位的 vec 向量。 * ---------------------------- */ #ifndef TPR_U8_VEC_H #define TPR_U8_VEC_H //-------------------- CPP --------------------// #include <cmath> //-- 少数场合会用到的 vec2 ---- // 不推荐大规模使用 // 希望简化类型种类,尽可能统一到 int,double 中去 class U8Vec2{ public: U8Vec2() = default; U8Vec2( uint8_t x_, uint8_t y_ ): x(x_), y(y_) {} inline void clear_all() noexcept { this->x = 0; this->y = 0; } //======== vals ========// uint8_t x {0}; uint8_t y {0}; }; #endif
turesnake/tprPixelGames
src/Engine/gameObj/createGo/create_go_oth.h
/* * ===================== create_go_oth.h ========================== * -- tpr -- * CREATE -- 2019.04.12 * MODIFY -- * ---------------------------------------------------------- * 通用的 辅助函数 * --------------- */ #ifndef TPR_CREATE_GO_OTH_H #define TPR_CREATE_GO_OTH_H //-------------------- CPP --------------------// #include <string> //-------------------- Engine --------------------// #include "tprAssert.h" #include "tprCast.h" #include "IntVec.h" #include "GameObjType.h" #include "Density.h" namespace gameObjs{//------------- namespace gameObjs ---------------- /* =========================================================== * apply_isFlipOver * ----------------------------------------------------------- * 是否左右翻转 * param: fieldWeight_ -- [-100.0, 100.0] */ /* inline bool apply_isFlipOver( double fieldWeight_ ){ size_t randV = cast_2_size_t(floor(fieldWeight_ * 3.1 + 911.3)); return ((randV%10)<5); } */ /* =========================================================== * apply_isSingleTRunk * ----------------------------------------------------------- * 树,主干是否分叉 * param: fieldWeight_ -- [-100.0, 100.0] */ /* inline bool apply_isSingleTRunk( double fieldWeight_ )noexcept{ size_t randV = cast_2_size_t(floor(fieldWeight_ * 3.7 + 701.7)); return ((randV%10)<5); } */ /* =========================================================== * apply_a_oakId tmp * ----------------------------------------------------------- * 这组方法很临时。不够好... * param: fieldWeight_ -- [-100.0, 100.0] */ /* inline size_t apply_a_simpleId( double fieldWeight_, size_t _totalNum )noexcept{ size_t randV = cast_2_size_t(floor(fieldWeight_ * 5.3 + 977.1)); return randV % _totalNum; } */ /* =========================================================== * apply_treeAge_by_density tmp * ----------------------------------------------------------- */ inline int apply_treeAge_by_density( Density _density )noexcept{ switch( _density.get_lvl() ){ case -3: return 3; //- tmp case -2: return 2; //- tmp case -1: return 1; //- tmp case 1: return 1; case 2: return 2; case 3: return 3; default: tprAssert(0); return 3; //- never reach } } inline size_t apply_randUVal_in_range( size_t randUVal_, size_t begVal_, size_t endVal_, bool isIncludebeg_=true, bool isIncludeEnd_=true )noexcept{ size_t fst = isIncludebeg_ ? begVal_ : (begVal_+1); // include fst size_t lst = isIncludeEnd_ ? endVal_ : (endVal_-1); // include lst size_t off = lst - fst + 1; // include lst size_t ret = ((randUVal_+25533) % off) + fst; return ret; } }//------------- namespace gameObjs: end ---------------- #endif
turesnake/tprPixelGames
src/Engine/map/chunkCreateRelease/chunkCreate.h
/* * =================== chunkCreate.h ======================= * -- tpr -- * CREATE -- 2019.02.23 * MODIFY -- * ---------------------------------------------------------- * chunk build api * ---------------------------- */ #ifndef TPR_CHUNK_BUILD_H #define TPR_CHUNK_BUILD_H //------------------- CPP --------------------// #include <vector> #include <utility> #include <optional> //-------------------- Engine --------------------// #include "IntVec.h" #include "fieldKey.h" #include "chunkKey.h" namespace chunkCreate {//------- namespace: chunkCreate ----------// void create_9_chunks( IntVec2 playerMPos_ ); void collect_chunks_need_to_be_create_in_update(); void create_chunks_from_waitingQue(); //-- 基于多线程的 新模块 -- std::optional<chunkKey_t> chunkCreate_3_receive_data_and_create_one_chunk(); void collect_ecoObjs_need_to_be_create(); }//----------------- namespace: chunkCreate: end -------------------// #endif
turesnake/tprPixelGames
src/Engine/gameObj/goDataForCreate/GoDataForCreate.h
/* * ===================== GoDataForCreate.h ========================== * -- tpr -- * CREATE -- 2019.12.02 * MODIFY -- * ---------------------------------------------------------- */ #ifndef TPR_GO_DATA_FOR_CREATE_H #define TPR_GO_DATA_FOR_CREATE_H #include "pch.h" //------------------- CPP --------------------// #include <variant> //------------------- Engine --------------------// #include "GameObjType.h" #include "NineDirection.h" #include "BrokenLvl.h" #include "FloorGoType.h" #include "animSubspeciesId.h" #include "AnimActionEName.h" #include "GoAltiRange.h" #include "GoAssemblePlan.h" #include "DyBinary.h" // need: class Job_Field; class Job_GroundGoEnt; // 生成一个go实例,需要的基本数据 // - 在 ecoobj 生成阶段,此数据被创建,并永久存储在 ecoobj 中 // - 以 const 指针 的形式,被传递到 job chunk/filed, 以及 具象go类中 // 所以,不用担心此数据的 容量 class GoDataForCreate{ public: GoDataForCreate()=default; class GoMeshBase; class GoMeshByLink; class GoMeshByHand; //========== Self Vals ==========// static std::unique_ptr<GoDataForCreate> create_new_goDataForCreate( IntVec2 mpos_, const glm::dvec2 &dpos_, // 让外部计算好 goSpeciesId_t goSpeciesId_, goLabelId_t goLabelId_, NineDirection direction_, // 未来支持从 GoSpecFromJson 中提取默认值 BrokenLvl brokenLvl_, // 未来支持从 GoSpecFromJson 中提取默认值 size_t ExtraGoUWeight_=0 // 刷怪笼赋予的 累加随机数,mapEntGo 无需关心 ); static std::unique_ptr<GoDataForCreate> create_new_floorGoDataForCreate( IntVec2 mpos_, const glm::dvec2 &dpos_, // 让外部计算好 goSpeciesId_t goSpeciesId_, goLabelId_t goLabelId_, NineDirection direction_ // 未来支持从 GoSpecFromJson 中提取默认值 ); static std::unique_ptr<GoDataForCreate> create_new_groundGoDataForCreate( const Job_Field &jobFieldRef_, const std::vector<std::unique_ptr<Job_GroundGoEnt>> &groundGoEnts_ ); //----- get -----// inline goSpeciesId_t get_goSpeciesId()const noexcept{ return this->goSpeciesId; } inline goLabelId_t get_goLabelId()const noexcept{ return this->goLabelId; } inline const glm::dvec2 &get_dpos()const noexcept{ return this->dpos; } inline NineDirection get_direction()const noexcept{ return this->direction; } inline BrokenLvl get_brokenLvl()const noexcept{ return this->brokenLvl; } inline GoAltiRangeLabel get_goAltiRangeLabel()const noexcept{ return this->goAltiRangeLabel; } inline size_t get_goUWeight()const noexcept{ return this->goUWeight; } inline const ColliDataFromJson *get_colliDataFromJsonPtr()const noexcept{ return this->colliDataFromJsonPtr; } inline DyBinary &get_binary()noexcept{ return this->binary; } inline const DyBinary &get_binary()const noexcept{ return this->binary; } inline const std::vector<std::shared_ptr<GoMeshBase>> &get_goMeshs_autoInit()const noexcept{ return this->goMeshs_autoInit; } inline const std::vector<std::shared_ptr<GoMeshBase>> &get_goMeshs_notAutoInit()const noexcept{ return this->goMeshs_notAutoInit; } private: //========== vals ==========// goSpeciesId_t goSpeciesId {}; goLabelId_t goLabelId {}; glm::dvec2 dpos {}; // go 绝对 dpos NineDirection direction {NineDirection::Center}; //- 角色 动画朝向 BrokenLvl brokenLvl {}; GoAltiRangeLabel goAltiRangeLabel {}; size_t goUWeight {}; // mix mapEntUWeight, goSpeciesId, goLabelId const ColliDataFromJson *colliDataFromJsonPtr {nullptr}; //bool isNeedWind {}; // 是否需要生成 风吹值,暂时 始终为 true DyBinary binary {}; // customized data std::vector<std::shared_ptr<GoMeshBase>> goMeshs_autoInit {}; std::vector<std::shared_ptr<GoMeshBase>> goMeshs_notAutoInit {}; }; // interface class GoDataForCreate::GoMeshBase{ public: GoMeshBase()=default; virtual ~GoMeshBase()=default; //--- virtual const std::string &get_goMeshName()const =0; virtual const std::string &get_animFrameSetName()const =0; virtual glm::dvec2 get_dposOff()const =0; virtual double get_zOff()const =0; virtual const std::string &get_animLabel()const =0; virtual AnimActionEName get_animActionEName()const =0; virtual RenderLayerType get_renderLayerType()const =0; virtual ShaderType get_shaderType()const =0; virtual bool get_isVisible()const =0; //--- virtual animSubspeciesId_t get_subspeciesId()const =0; virtual size_t get_windDelayIdx()const =0; virtual size_t get_uWeight()const =0; virtual FloorGoLayer get_floorGoLayer()const =0; }; // 推荐的方案 // 当需要的 gomesh 数据,直接可以从 GoAssemblePlanSet::GoMeshEnt 中取得时, // 使用此方案。 class GoDataForCreate::GoMeshByLink : public GoDataForCreate::GoMeshBase{ public: GoMeshByLink( const GoAssemblePlanSet::GoMeshEnt *goMeshEntPtr_, size_t uWeight_ ): goMeshEntPtr(goMeshEntPtr_), uWeight(uWeight_) { tprAssert( this->goMeshEntPtr ); tprAssert( this->uWeight != 0 ); this->init_subspeciesId(); } //------- set -------// inline void set_windDelayIdx( size_t windDelayIdx_ )noexcept{ this->windDelayIdx = windDelayIdx_; } //---- get vals by link -----// inline const std::string &get_goMeshName()const override{ return this->goMeshEntPtr->goMeshName;} inline const std::string &get_animFrameSetName()const override{ return this->goMeshEntPtr->animFrameSetName; } inline glm::dvec2 get_dposOff()const override{ return this->goMeshEntPtr->dposOff; } inline double get_zOff()const override{ return this->goMeshEntPtr->zOff; } inline const std::string &get_animLabel()const override{ return this->goMeshEntPtr->animLabel; } inline AnimActionEName get_animActionEName()const override{ return this->goMeshEntPtr->animActionEName; } inline RenderLayerType get_renderLayerType()const override{ return this->goMeshEntPtr->renderLayerType; } inline ShaderType get_shaderType()const override{ return this->goMeshEntPtr->shaderType; } inline bool get_isVisible()const override{ return this->goMeshEntPtr->isVisible; } //------- real optional vals -------// inline FloorGoLayer get_floorGoLayer()const override{ tprAssert( this->goMeshEntPtr->floorGoLayer.has_value() ); return this->goMeshEntPtr->floorGoLayer.value(); } //--- vals not in goMeshEntPtr -----// inline animSubspeciesId_t get_subspeciesId()const override{ return this->subspeciesId; } inline size_t get_windDelayIdx()const override{ return this->windDelayIdx; } inline size_t get_uWeight()const override{ return this->uWeight; } private: void init_subspeciesId()noexcept; const GoAssemblePlanSet::GoMeshEnt *goMeshEntPtr {nullptr}; //--- vals not in goMeshEntPtr -----// animSubspeciesId_t subspeciesId {}; size_t windDelayIdx {}; // only used in windClock size_t uWeight {}; // goMPos.uWeight + 一组有序的素数(按照 gomesh 排序) }; // 手动装填的方案 // 适合动态 组建一些 gomesh,而不是用现成的。 // 比如用于 GroundGo 时 class GoDataForCreate::GoMeshByHand : public GoDataForCreate::GoMeshBase{ public: // auto GoMeshByHand( const GoAssemblePlanSet::GoMeshEnt *goMeshEntPtr_, size_t uWeight_ ): goMeshEntPtr(goMeshEntPtr_), uWeight(uWeight_) { tprAssert( this->goMeshEntPtr ); tprAssert( this->uWeight != 0 ); this->init_subspeciesId(this->goMeshEntPtr->animFrameSetName, this->goMeshEntPtr->animLabel, this->uWeight ); } // 需要手动指定 afsName,animLabel 的版本 GoMeshByHand( const GoAssemblePlanSet::GoMeshEnt *goMeshEntPtr_, const std::string &animFrameSetName_, const std::string &animLabel_, size_t uWeight_ ): goMeshEntPtr(goMeshEntPtr_), animFrameSetName( {animFrameSetName_} ), animLabel( {animLabel_} ), uWeight(uWeight_) { tprAssert( this->goMeshEntPtr ); tprAssert( this->uWeight != 0 ); this->init_subspeciesId(animFrameSetName_, animLabel_, uWeight_ ); } //------- set -------// inline void set_windDelayIdx( size_t windDelayIdx_ )noexcept{ this->windDelayIdx = windDelayIdx_; } //----- customized vals ----------// inline const std::string &get_goMeshName()const override{ return this->goMeshName.has_value() ? this->goMeshName.value() : this->goMeshEntPtr->goMeshName; } inline const std::string &get_animFrameSetName()const override{ return this->animFrameSetName.has_value() ? this->animFrameSetName.value() : this->goMeshEntPtr->animFrameSetName; } inline glm::dvec2 get_dposOff()const override{ return this->dposOff.has_value() ? this->dposOff.value() : this->goMeshEntPtr->dposOff; } inline double get_zOff()const override{ return this->zOff.has_value() ? this->zOff.value() : this->goMeshEntPtr->zOff; } inline const std::string &get_animLabel()const override{ return this->animLabel.has_value() ? this->animLabel.value() : this->goMeshEntPtr->animLabel; } inline AnimActionEName get_animActionEName()const override{ return this->animActionEName.has_value() ? this->animActionEName.value() : this->goMeshEntPtr->animActionEName; } inline RenderLayerType get_renderLayerType()const override{ return this->renderLayerType.has_value() ? this->renderLayerType.value() : this->goMeshEntPtr->renderLayerType; } inline ShaderType get_shaderType()const override{ return this->shaderType.has_value() ? this->shaderType.value() : this->goMeshEntPtr->shaderType; } inline bool get_isVisible()const override{ return this->isVisible.has_value() ? this->isVisible.value() : this->goMeshEntPtr->isVisible; } //------- real optional vals -------// inline FloorGoLayer get_floorGoLayer()const override{ if( this->floorGoLayer.has_value() ){ return this->floorGoLayer.value(); }else{ tprAssert( this->goMeshEntPtr->floorGoLayer.has_value() ); return this->goMeshEntPtr->floorGoLayer.value(); } } //--- vals not in goMeshEntPtr -- inline animSubspeciesId_t get_subspeciesId()const override{ return this->subspeciesId; } inline size_t get_windDelayIdx()const override{ return this->windDelayIdx; } inline size_t get_uWeight()const override{ return this->uWeight; } //===== values =====// //----- customized vals ----------// std::optional<std::string> goMeshName {}; // 索引key //=== std::optional<glm::dvec2> dposOff {}; // gomesh-dposoff based on go-dpos std::optional<double> zOff {}; std::optional<AnimActionEName> animActionEName {}; std::optional<RenderLayerType> renderLayerType {}; std::optional<ShaderType> shaderType {}; std::optional<bool> isVisible {}; std::optional<bool> isAutoInit {}; std::optional<NineDirection> default_dir {}; std::optional<BrokenLvl> default_brokenLvl {}; //------- real optional vals -------// std::optional<FloorGoLayer> floorGoLayer { std::nullopt }; // only for FloorGo private: void init_subspeciesId( const std::string &animFrameSetName_, const std::string &label_, size_t uWeight_ )noexcept; //===== values =====// const GoAssemblePlanSet::GoMeshEnt *goMeshEntPtr {nullptr}; //----- customized vals ----------// std::optional<std::string> animFrameSetName {}; std::optional<std::string> animLabel {}; //--- vals not in goMeshEntPtr -----// animSubspeciesId_t subspeciesId {}; size_t windDelayIdx {}; // only used in windClock size_t uWeight {}; // goMPos.uWeight + 一组有序的素数(按照 gomesh 排序) }; #endif
turesnake/tprPixelGames
src/Engine/tools/FloatVec.h
<filename>src/Engine/tools/FloatVec.h /* * ========================= FloatVec.h ========================== * -- tpr -- * CREATE -- 2019.09.22 * MODIFY -- * ---------------------------------------------------------- */ #ifndef TPR_FLOAT_VEC_H #define TPR_FLOAT_VEC_H //--- glm - 0.9.9.5 --- #include "glm_no_warnings.h" //-------------------- Engine --------------------// #include "tprMath.h" #include "RGBA.h" struct FloatVec2{ float x {0.0f}; float y {0.0f}; }; inline FloatVec2 glmDvec2_2_floatVec2( const glm::dvec2 dv_ ){ return FloatVec2{ static_cast<float>(dv_.x), static_cast<float>(dv_.y), }; } //-- used for ubo -- struct FloatVec3{ float x {0.0f}; float y {0.0f}; float z {0.0f}; //--- operator += ... ---// inline FloatVec3& operator += ( const FloatVec3 &a_ ) noexcept { this->x += a_.x; this->y += a_.y; this->z += a_.z; return *this; } inline FloatVec3& operator += ( float f_ ) noexcept { this->x += f_; this->y += f_; this->z += f_; return *this; } inline FloatVec3& operator *= ( float s_ ) noexcept { this->x *= s_; this->y *= s_; this->z *= s_; return *this; } }; inline FloatVec3 operator + ( FloatVec3 a_, FloatVec3 b_ ) noexcept { return FloatVec3 { a_.x+b_.x, a_.y+b_.y, a_.z+b_.z }; } inline FloatVec3 operator - ( FloatVec3 a_, FloatVec3 b_ ) noexcept { return FloatVec3 { a_.x-b_.x, a_.y-b_.y, a_.z-b_.z }; } inline FloatVec3 operator + ( FloatVec3 a_, float f_ ) noexcept { return FloatVec3 { a_.x+f_, a_.y+f_, a_.z+f_ }; } inline FloatVec3 operator - ( FloatVec3 a_, float f_ ) noexcept { return FloatVec3 { a_.x-f_, a_.y-f_, a_.z-f_ }; } inline FloatVec3 operator * ( FloatVec3 a_, float f_ ) noexcept { return FloatVec3 { a_.x*f_, a_.y*f_, a_.z*f_ }; } inline bool is_closeEnough( const FloatVec3 &a_, const FloatVec3 &b_, float threshold_ )noexcept{ return (is_closeEnough<float>(a_.x, b_.x, threshold_) && is_closeEnough<float>(a_.y, b_.y, threshold_) && is_closeEnough<float>(a_.z, b_.z, threshold_) ); } inline FloatVec3 rgba_2_floatVec3( const RGBA &rgba_ )noexcept{ float r = static_cast<float>(rgba_.r) / 255.0f; // [0.0, 1.0] float g = static_cast<float>(rgba_.g) / 255.0f; // [0.0, 1.0] float b = static_cast<float>(rgba_.b) / 255.0f; // [0.0, 1.0] // ignore alpha return FloatVec3{ r, g, b }; } //-- used for ubo -- struct FloatVec4{ float r {0.0f}; float g {0.0f}; float b {0.0f}; float a {0.0f}; //--- operator += ... ---// inline FloatVec4& operator += ( const FloatVec4 &a_ ) noexcept { this->r += a_.r; this->g += a_.g; this->b += a_.b; this->a += a_.a; return *this; } }; inline FloatVec4 floatVec3_2_floatVec4( const FloatVec3 &v_, float alpha_ )noexcept{ return FloatVec4{ v_.x, v_.y, v_.z, alpha_ }; } inline FloatVec3 floatVec4_2_floatVec3( const FloatVec4 &v_ )noexcept{ return FloatVec3{ v_.r, v_.g, v_.b }; } /* =========================================================== * operator +, -, * * ----------------------------------------------------------- */ inline FloatVec4 operator + ( const FloatVec4 &a_, const FloatVec4 &b_ )noexcept{ return FloatVec4 { a_.r + b_.r, a_.g + b_.g, a_.b + b_.b, a_.a + b_.a }; } inline FloatVec4 operator - ( const FloatVec4 &a_, const FloatVec4 &b_ )noexcept{ return FloatVec4 { a_.r - b_.r, a_.g - b_.g, a_.b - b_.b, a_.a - b_.a }; } inline FloatVec4 operator * ( const FloatVec4 &a_, float s_ )noexcept{ return FloatVec4 { a_.r * s_, a_.g * s_, a_.b * s_, a_.a * s_ }; } //-- include alpha channel -- inline bool is_closeEnough( const FloatVec4 &a_, const FloatVec4 &b_, float threshold_ )noexcept{ return (is_closeEnough<float>(a_.r, b_.r, threshold_) && is_closeEnough<float>(a_.g, b_.g, threshold_) && is_closeEnough<float>(a_.b, b_.b, threshold_) && is_closeEnough<float>(a_.a, b_.a, threshold_) ); } inline bool is_closeEnough_without_alpha( const FloatVec4 &a_, const FloatVec4 &b_, float threshold_ )noexcept{ return (is_closeEnough<float>(a_.r, b_.r, threshold_) && is_closeEnough<float>(a_.g, b_.g, threshold_) && is_closeEnough<float>(a_.b, b_.b, threshold_) ); } #endif
turesnake/tprPixelGames
src/Engine/gameObj/PubBinary2.h
/* * ==================== PubBinary2.h ===================== * -- tpr -- * CREATE -- 2019.07.03 * MODIFY -- * ---------------------------------------------------------- */ #ifndef TPR_PUB_BINARY_2_H #define TPR_PUB_BINARY_2_H //-------------------- Engine --------------------// #include "tprAssert.h" // 简易版 // 等 元素扩充后,再再存储上做优化 ... class PubBinary2{ public: int HP {}; // nil = -999 int MP {}; // nil = -999 //... }; #endif
turesnake/tprPixelGames
src/Engine/input/KeyBoardKey_2_GameKey_map.h
<reponame>turesnake/tprPixelGames<gh_stars>100-1000 /* * ================= KeyBoardKey_2_GameKey_map ========================== * -- tpr -- * CREATE -- 2020.01.29 * MODIFY -- * ---------------------------------------------------------- * only include by input.cpp * --- */ #ifndef TPR_KEYBOARD_KEY_2_GAMEKEY_MAP_H #define TPR_KEYBOARD_KEY_2_GAMEKEY_MAP_H #include <unordered_map> #include "KeyBoard.h" #include "GameKey.h" // 按键映射表 // 未来,实现 按键修改界面后,这组值可被用户改写,存储进 json / db inline std::unordered_map<KeyBoard::Key, GameKey> KeyBoardKey_2_GameKey_map{ {KeyBoard::Key::ENTER, GameKey::A}, {KeyBoard::Key::H, GameKey::A}, {KeyBoard::Key::J, GameKey::B}, {KeyBoard::Key::K, GameKey::X}, {KeyBoard::Key::L, GameKey::Y}, {KeyBoard::Key::Q, GameKey::LB}, {KeyBoard::Key::E, GameKey::RB}, {KeyBoard::Key::BACKSPACE, GameKey::Back}, {KeyBoard::Key::DELETE_, GameKey::Back}, {KeyBoard::Key::ESCAPE, GameKey::Back}, {KeyBoard::Key::TAB, GameKey::Start}, {KeyBoard::Key::F1, GameKey::Guide}, {KeyBoard::Key::F2, GameKey::LeftThumb}, {KeyBoard::Key::F3, GameKey::RightThumb}, {KeyBoard::Key::NUM_1, GameKey::Hat_Up}, {KeyBoard::Key::NUM_2, GameKey::Hat_Right}, {KeyBoard::Key::NUM_3, GameKey::Hat_Down}, {KeyBoard::Key::NUM_4, GameKey::Hat_Left} }; #endif
turesnake/tprPixelGames
src/Engine/scene/sceneLoopInn.h
/* * ==================== sceneLoopInn.h ======================= * -- tpr -- * CREATE -- 2019.04.29 * MODIFY -- * ---------------------------------------------------------- * * ---------------------------- */ #ifndef TPR_SCENE_LOOP_INN_H #define TPR_SCENE_LOOP_INN_H //void sceneLogicLoop_firstPlayInputSet(); //void sceneRenderLoop_firstPlayInputSet(); void sceneLogicLoop_begin(); void sceneRenderLoop_begin(); void sceneLogicLoop_world(); void sceneRenderLoop_world(); #endif
turesnake/tprPixelGames
src/Engine/map/MapField.h
<filename>src/Engine/map/MapField.h<gh_stars>100-1000 /* * ===================== MapField.h ======================= * -- tpr -- * CREATE -- 2019.02.27 * MODIFY -- * ---------------------------------------------------------- * 4*4mapent 构成一个 field [第二版] * ---------------------------- */ #ifndef TPR_MAP_FIELD_H #define TPR_MAP_FIELD_H #include "pch.h" //-------------------- Engine --------------------// #include "EcoSysPlanType.h" #include "MapCoord.h" #include "chunkKey.h" #include "sectionKey.h" #include "fieldKey.h" #include "RGBA.h" #include "MapAltitude.h" #include "occupyWeight.h" #include "Density.h" #include "colorTableId.h" class MemMapEnt; //-- 4*4mapent 构成一个 field -- [just mem] class MapField{ public: explicit MapField( IntVec2 anyMPos_ ): mpos( anyMPos_2_fieldMPos(anyMPos_) ) { this->init(); } inline bool is_land() const noexcept{ return (this->get_maxMapAlti().is_land()); } //---------- init ----------// inline void init_ecoObjKey(sectionKey_t key_)noexcept{ tprAssert(!this->ecoObjKey.has_value()); this->ecoObjKey = {key_}; } inline void init_colorTableId(colorTableId_t id_)noexcept{ tprAssert(!this->colorTableId.has_value()); this->colorTableId = {id_}; } inline void init_density(Density d_)noexcept{ tprAssert(!this->density.has_value()); this->density = {d_}; } inline void init_nodeMapAlti(MapAltitude alti_)noexcept{ tprAssert(!this->nodeMapAlti.has_value()); this->nodeMapAlti = {alti_}; } inline void init_minAlti(MapAltitude alti_)noexcept{ tprAssert(!this->minMapAlti.has_value()); this->minMapAlti = {alti_}; } inline void init_maxAlti(MapAltitude alti_)noexcept{ tprAssert(!this->maxMapAlti.has_value()); this->maxMapAlti = {alti_}; } inline void init_isCrossEcoObj( bool b_ )noexcept{ tprAssert(!this->isCrossEcoObj.has_value()); this->isCrossEcoObj = {b_}; } inline void init_isCrossColorTable( bool b_ )noexcept{ tprAssert(!this->isCrossColorTable.has_value()); this->isCrossColorTable = {b_}; } inline void init_uWeight( double v_ )noexcept{ tprAssert(!this->uWeight.has_value()); this->uWeight = {v_}; } //---------- get ----------// inline IntVec2 get_mpos()const noexcept{ tprAssert(this->mpos.has_value()); return this->mpos.value(); } inline glm::dvec2 get_dpos()const noexcept{ return mpos_2_dpos(this->get_mpos()); } inline glm::dvec2 get_midDPos()const noexcept{ return (this->get_dpos() + MapField::halfFieldVec2); } inline IntVec2 get_midMPos()const noexcept{ return (this->get_mpos() + IntVec2{ HALF_ENTS_PER_FIELD<>, HALF_ENTS_PER_FIELD<> }); } inline const glm::dvec2 &get_nodeDPos()const noexcept{ tprAssert(this->nodeDPos.has_value()); return this->nodeDPos.value(); } inline MapAltitude get_nodeMapAlti()const noexcept{ tprAssert(this->nodeMapAlti.has_value()); return this->nodeMapAlti.value(); } inline MapAltitude get_minMapAlti()const noexcept{ tprAssert(this->minMapAlti.has_value()); return this->minMapAlti.value(); } inline MapAltitude get_maxMapAlti()const noexcept{ tprAssert(this->maxMapAlti.has_value()); return this->maxMapAlti.value(); } inline fieldKey_t get_fieldKey()const noexcept{ tprAssert(this->fieldKey.has_value()); return this->fieldKey.value(); } inline Density get_density()const noexcept{ tprAssert(this->density.has_value()); return this->density.value(); } inline sectionKey_t get_ecoObjKey()const noexcept{ tprAssert(this->ecoObjKey.has_value()); return this->ecoObjKey.value(); } inline colorTableId_t get_colorTableId()const noexcept{ tprAssert(this->colorTableId.has_value()); return this->colorTableId.value(); } inline occupyWeight_t get_occupyWeight()const noexcept{ tprAssert(this->occupyWeight.has_value()); return this->occupyWeight.value(); } inline size_t get_uWeight()const noexcept{ tprAssert(this->uWeight.has_value()); return this->uWeight.value(); } private: void init(); void init_nodeDPos( const glm::dvec2 &FDPos_ ); void init_occupyWeight( const glm::dvec2 &FDPos_ ); //====== vals =======// std::optional<IntVec2> mpos {std::nullopt}; // [left-bottom] std::optional<fieldKey_t> fieldKey {std::nullopt}; std::optional<glm::dvec2> nodeDPos {std::nullopt}; //- field 内的一个随机点 ,绝对距离 Must align to pix std::optional<size_t> uWeight {std::nullopt}; //- 打乱后的随机值,分布更均匀 [0, 9999] std::optional<occupyWeight_t> occupyWeight {std::nullopt}; //- 抢占权重。 [0,15] //- 数值越高,此 ecosys 越强势,能占据更多fields //- [just mem] std::optional<sectionKey_t> ecoObjKey {std::nullopt}; std::optional<colorTableId_t> colorTableId {std::nullopt}; // same as ecoObj.colorTableId std::optional<Density> density {std::nullopt}; std::optional<MapAltitude> nodeMapAlti {std::nullopt}; //- nodeMPos 点的 alti 值 std::optional<MapAltitude> minMapAlti {std::nullopt}; std::optional<MapAltitude> maxMapAlti {std::nullopt}; //- field 拥有的所有 mapent 的 中点pix 的,alti最低值,最大值 //- 默认初始值 需要反向设置 // 通过这组值,来表达 field 的 alti 信息 // --------- // 但在实际使用中,这组值并不完善,chunk边缘field 的 这组alti值往往无法被填完 // 就要开始 种go。此时很容易把 go 种到水里。 //===== flags =====// std::optional<bool> isCrossEcoObj {std::nullopt}; // 境内是否跨越 数个 ecoobj std::optional<bool> isCrossColorTable {std::nullopt}; // 境内是否跨越 数个 colortable //===== static =====// static constexpr glm::dvec2 halfFieldVec2 { HALF_PIXES_PER_FIELD_D, HALF_PIXES_PER_FIELD_D }; }; #endif
turesnake/tprPixelGames
src/Engine/tools/create_texNames.h
<filename>src/Engine/tools/create_texNames.h /* * ==================== create_texNames.h =================== * -- tpr -- * CREATE -- 2019.01.23 * MODIFY -- * ---------------------------------------------------------- */ #ifndef TPR_CREATE_TEXNAMES_H #define TPR_CREATE_TEXNAMES_H //=== *** glad FIRST, glfw SECEND *** === // Don't include glfw3.h ALONE!!! #include <glad/glad.h> //-------------------- CPP --------------------// #include <vector> //-------------------- Engine --------------------// #include "IntVec.h" #include "RGBA.h" /* =========================================================== * create_texNames * ----------------------------------------------------------- * param: texNum_ -- 要创建 几个 texName * param: imgWH_ -- 目标texture 的 宽度长度 * param: frame_data_ary_ -- 图形数据本体 * param: texNamesBuf_ -- 最终生成的 texNames 存入此容器 */ inline void create_texNames(size_t texNum_, IntVec2 imgWH_, const std::vector<std::vector<RGBA>> &frame_data_ary_, std::vector<GLuint> &texNamesBuf_ ){ texNamesBuf_.resize( texNum_ ); //-- 申请 _texNum个 tex实例,并获得其 names glGenTextures( static_cast<GLsizei>(texNum_), &texNamesBuf_.at(0) ); for( size_t i=0; i<texNum_; i++ ){ glBindTexture( GL_TEXTURE_2D, texNamesBuf_.at(i) ); //-- 为 GL_TEXTURE_2D 设置环绕、过滤方式 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); //-- 设置 S轴的 环绕方式 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); //-- 设置 T轴的 环绕方式 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); // 缩小时 纹理过滤 的策略 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); // 放大时 纹理过滤 的策略 //-- GL_NEAREST 临近过滤,8-bit 专用 //-- GL_LINEAR 线性过滤, const GLvoid *dptr = static_cast<const GLvoid*>(&(frame_data_ary_.at(i).at(0))); //-- 通过之前的 png图片数据,生成 一个 纹理。 glTexImage2D( GL_TEXTURE_2D, //-- 指定纹理目标/target, 0, //-- 多级渐远纹理的级别: 0: 基本级别 GL_RGBA, //-- 希望把纹理储存为何种格式 imgWH_.x, //-- 纹理的宽度 imgWH_.y, //-- 纹理的高度 0, //-- 总是被设为0(历史遗留问题 GL_RGBA, //-- 源图的 格式 GL_UNSIGNED_BYTE, //-- 源图的 数据类型 dptr //-- 图像数据 ); //-- 本游戏不需要 多级渐远 -- //glGenerateMipmap(GL_TEXTURE_2D); //-- 生成多级渐远纹理 } } /* =========================================================== * create_a_texName * ----------------------------------------------------------- * param: imgWH_ -- 目标texture 的 宽度长度 * param: imgDataPtr_ -- 图形数据本体 */ inline GLuint create_a_texName( IntVec2 imgWH_, const GLvoid *imgDataPtr_ ){ GLuint texName {}; //-- 申请 _texNum个 tex实例,并获得其 names glGenTextures( 1, &texName ); glBindTexture( GL_TEXTURE_2D, texName ); //-- 为 GL_TEXTURE_2D 设置环绕、过滤方式 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); //-- 设置 S轴的 环绕方式 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); //-- 设置 T轴的 环绕方式 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); // 缩小时 纹理过滤 的策略 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); // 放大时 纹理过滤 的策略 //-- GL_NEAREST 临近过滤,8-bit 专用 //-- GL_LINEAR 线性过滤, //-- 通过之前的 png图片数据,生成 一个 纹理。 glTexImage2D( GL_TEXTURE_2D, //-- 指定纹理目标/target, 0, //-- 多级渐远纹理的级别: 0: 基本级别 GL_RGBA, //-- 希望把纹理储存为何种格式 imgWH_.x, //-- 纹理的宽度 imgWH_.y, //-- 纹理的高度 0, //-- 总是被设为0(历史遗留问题 GL_RGBA, //-- 源图的 格式 GL_UNSIGNED_BYTE, //-- 源图的 数据类型 imgDataPtr_ //-- 图像数据 ); //-- 本游戏不需要 多级渐远 -- //glGenerateMipmap(GL_TEXTURE_2D); //-- 生成多级渐远纹理 return texName; } /* =========================================================== * create_a_empty_texName * ----------------------------------------------------------- * param: imgWH_ -- 目标texture 的 宽度长度 */ inline GLuint create_a_empty_texName( IntVec2 imgWH_ ){ GLuint texName {}; //-- 申请 _texNum个 tex实例,并获得其 names glGenTextures( 1, &texName ); glBindTexture( GL_TEXTURE_2D, texName ); //-- 为 GL_TEXTURE_2D 设置环绕、过滤方式 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); //-- 设置 S轴的 环绕方式 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); //-- 设置 T轴的 环绕方式 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); // 缩小时 纹理过滤 的策略 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); // 放大时 纹理过滤 的策略 //-- GL_NEAREST 临近过滤,8-bit 专用 //-- GL_LINEAR 线性过滤, //-- 通过之前的 png图片数据,生成 一个 纹理。 glTexImage2D( GL_TEXTURE_2D, //-- 指定纹理目标/target, 0, //-- 多级渐远纹理的级别: 0: 基本级别 GL_RGBA, //-- 希望把纹理储存为何种格式 imgWH_.x, //-- 纹理的宽度 imgWH_.y, //-- 纹理的高度 0, //-- 总是被设为0(历史遗留问题 GL_RGBA, //-- 源图的 格式 GL_UNSIGNED_BYTE, //-- 源图的 数据类型 nullptr //-- 图像数据, 为空 ); //-- 本游戏不需要 多级渐远 -- //glGenerateMipmap(GL_TEXTURE_2D); //-- 生成多级渐远纹理 return texName; } #endif
turesnake/tprPixelGames
src/Engine/animFrameSet/AnimActionPos.h
/* * ===================== AnimActionPos.h ========================== * -- tpr -- * CREATE -- 2019.08.31 * MODIFY -- * ---------------------------------------------------------- * animFrameSet 中,单张 图元帧 拥有的 全部 pos数据集 */ #ifndef TPR_ANIM_ACTION_POS_H #define TPR_ANIM_ACTION_POS_H #include "pch.h" //-------------------- Engine --------------------// #include "GoAltiRange.h" #include "ColliderType.h" #include "ColliDataFromJson.h" #include "ID_Manager.h" using animActionPosId_t = uint32_t; //- animActionPos id type //-- 仅用来描述 animFrameSet,所以必须是 静态数据 --// // 每个 animAction 实例,分配一份 class AnimActionPos{ public: AnimActionPos() = default; void set_rootAnchorDPosOff( const glm::dvec2 &dposOff_ )noexcept{ this->rootAnchorDPosOff = dposOff_; } inline const glm::dvec2 &get_rootAnchorDPosOff() const noexcept{ return this->rootAnchorDPosOff; } //======== static ========// static ID_Manager id_manager; //- 负责生产 animActionPos_id private: glm::dvec2 rootAnchorDPosOff {}; //-- 最原始的数据,从 图元帧左下角ppos,到 rootAnchor点的 fposOff //-- *** 不用对齐于 mapEnt *** //-- 目前仅被用于 ChildMesh 渲染用 }; #endif
turesnake/tprPixelGames
src/Engine/collision/ColliPoint.h
/* * ======================= ColliPoint.h ========================== * -- tpr -- * CREATE -- 2019.08.29 * MODIFY -- * ---------------------------------------------------------- */ #ifndef TPR_COLLI_POINT_H #define TPR_COLLI_POINT_H // 用于 技能碰撞检测 // 如果一个 animAction 内发动了技能,那么其 anim.J.png 中,有那么几帧,会携带 ColliPoint 信息 // colliPoint 是一个 点(ppos),程序记录这个点,到 rootAnchor 的偏移距离 // --- // 一组 colliPoint 点(比如五六个)可以表达一个 技能的碰撞区域。 // --- // 每次执行碰撞检测时: // --1-- 遍历本帧的 所有 colliPoints,计算出其所在的 mapent。将这些 mapent,收集到一个 临时容器中 // 如果一个 colliPoint,在 mapent 中的位置 过于边缘,此 mapent 将不会被命中 // 这反过来要求, colliPoint 在 J.png 中的布置必须合理,技能碰撞区 最好大一些 // --2-- 遍历上文收集的 mapent集,逐个执行 碰撞检测 // class ColliPoint{ public: }; #endif
turesnake/tprPixelGames
src/Engine/multiThread/chunkCreate/Job_Chunk.h
<reponame>turesnake/tprPixelGames /* * ======================= Job_Chunk.h ======================= * -- tpr -- * CREATE -- 2019.04.24 * MODIFY -- * ---------------------------------------------------------- * 以 chunk 为单位的,需要被 job线程 计算生成的 数据集 * ---------------------------- */ #ifndef TPR_JOB_CHUNK_H #define TPR_JOB_CHUNK_H //-------------------- CPP --------------------// #include <vector> //-------------------- Engine --------------------// #include "tprCast.h" #include "tprAssert.h" #include "config.h" #include "MapTexture.h" #include "MapAltitude.h" #include "fieldKey.h" #include "chunkKey.h" #include "Job_MapEnt.h" #include "Job_Field.h" #include "MapField.h" class Job_Chunk{ public: explicit Job_Chunk( chunkKey_t chunkKey_ ): chunkKey(chunkKey_), chunkMPos(chunkKey_2_mpos(chunkKey_)) { this->init(); } void write_2_field_from_jobData(); void create_field_goSpecDatas(); bool is_mapEnt_a_ecoBorder( IntVec2 mposOff_ )noexcept; inline chunkKey_t get_chunkKey()const noexcept{ return this->chunkKey; } inline IntVec2 get_chunkMPos()const noexcept{ return this->chunkMPos; } inline Job_MapEnt &getnc_mapEntInnRef( IntVec2 mposOff_ )noexcept{ tprAssert( (mposOff_.x>=0) && (mposOff_.x<ENTS_PER_CHUNK<>) && (mposOff_.y>=0) && (mposOff_.y<ENTS_PER_CHUNK<>) ); size_t idx = cast_2_size_t(mposOff_.y * ENTS_PER_CHUNK<> + mposOff_.x); tprAssert( idx < this->mapEntInns.size() ); return *(this->mapEntInns.at(idx)); } inline void insert_a_entInnPtr_2_field( fieldKey_t fieldKey_, IntVec2 mposOff_, Job_MapEnt* entPtr_ )noexcept{ tprAssert( this->job_fields.find(fieldKey_) != this->job_fields.end() ); this->job_fields.at(fieldKey_)->insert_a_entInnPtr( mposOff_, entPtr_ ); } /* inline void apply_field_job_groundGoEnts( fieldKey_t fieldKey_ )noexcept{ tprAssert( this->job_fields.find(fieldKey_) != this->job_fields.end() ); this->job_fields.at(fieldKey_)->apply_groundGoEnts(); } */ inline void set_field_min_max_altis( fieldKey_t fieldKey_, MapAltitude min_, MapAltitude max_ )noexcept{ tprAssert( this->fields.find(fieldKey_) != this->fields.end() ); auto *fieldPtr = this->fields.at(fieldKey_).get(); fieldPtr->init_minAlti( min_ ); fieldPtr->init_maxAlti( max_ ); } inline const Job_Field *get_job_fieldPtr( fieldKey_t fieldKey_ )const noexcept{ tprAssert( this->job_fields.find(fieldKey_) != this->job_fields.end() ); return this->job_fields.at(fieldKey_).get(); } inline MapField &getnc_fieldRef( fieldKey_t fieldKey_ )noexcept{ tprAssert( this->fields.find(fieldKey_) != this->fields.end() ); return *(this->fields.at(fieldKey_)); } inline std::unordered_map<fieldKey_t, std::unique_ptr<MapField>> & get_fields()noexcept{ return this->fields; } private: void init()noexcept; //------ chunkKey_t chunkKey {}; IntVec2 chunkMPos {}; std::vector<std::unique_ptr<Job_MapEnt>> mapEntInns {};// [32 * 32 mapents] std::unordered_map<fieldKey_t, std::unique_ptr<Job_Field>> job_fields {}; std::unordered_map<fieldKey_t, std::unique_ptr<MapField>> fields {}; // 在 job线程 直接创建 field 实例 // 最后一股脑传递给 主线程 }; #endif
turesnake/tprPixelGames
src/Engine/time/WindClock.h
/* * ========================= WindClock.h ========================== * -- tpr -- * CREATE -- 2019.10.18 * MODIFY -- * ---------------------------------------------------------- * control the grass anim * ---------------------------- */ #ifndef TPR_WIND_CLOCK_H #define TPR_WIND_CLOCK_H //--- glm - 0.9.9.5 --- #include "glm_no_warnings.h" //------------------- CPP --------------------// #include <cmath> #include <vector> //------------------- Engine --------------------// #include "tprAssert.h" class WindClock{ public: WindClock()=default; void init()noexcept; inline void update()noexcept{ //--- clockStep ---// this->clockStep--; if( this->clockStep <= 0 ){ this->reflesh_clockStep(); this->clockCount++; } //--- playSpeedScale ---// this->playSpeedScalePoolIdx++; if( this->playSpeedScalePoolIdx >= this->playSpeedScalePool.size() ){ this->playSpeedScalePoolIdx = 0; } } //----- get -----// inline size_t get_clockCount()const noexcept{ return this->clockCount; } inline double get_playSpeedScale( size_t offIdx_=0 )const noexcept{ size_t idx = (this->playSpeedScalePoolIdx + offIdx_) % this->playSpeedScalePool.size(); return this->playSpeedScalePool.at(idx); } private: inline void reflesh_clockStep()noexcept{ this->clockStep = this->clockStepPool.at( this->clockStepPoolIdx ); this->clockStepPoolIdx++; if( this->clockStepPoolIdx >= this->clockStepPool.size() ){ this->clockStepPoolIdx = 0; } } //--- vals ---// size_t clockCount {0}; size_t clockStep {}; std::vector<size_t> clockStepPool {}; // 100 dynamic clockStep-vals size_t clockStepPoolIdx {0}; //--- std::vector<double> playSpeedScalePool {}; size_t playSpeedScalePoolIdx {0}; }; size_t calc_goMesh_windDelayIdx( const glm::dvec2 &dpos_ )noexcept; #endif
turesnake/tprPixelGames
src/Engine/tools/BoolBitMap.h
<reponame>turesnake/tprPixelGames /* * ======================= BoolBitMap.h ======================= * -- tpr -- * CREATE -- 2019.02.03 * MODIFY -- * ---------------------------------------------------------- * each bit mean a bool_flag * ---------------------------- */ #ifndef TPR_BOOL_BIT_MAP_H #define TPR_BOOL_BIT_MAP_H //-------------------- CPP --------------------// #include <cmath> #include <vector> //-------------------- Engine --------------------// #include "tprAssert.h" #include "tprCast.h" //- each bit: // 0: false // 1: true class BoolBitMap{ public: BoolBitMap() = default; inline void resize( size_t w_, size_t h_=1 )noexcept{ this->wLen = w_; this->hLen = h_; this->totalNum = w_ * h_; //-- size_t bytes = cast_2_size_t( ceil( static_cast<double>(this->totalNum) / static_cast<double>(BoolBitMap::BITS_PER_BYTE) ) ); bitMap.resize( bytes ); } inline void clear_all()noexcept{ for( auto &i : bitMap ){ i = 0; //- all false } } inline void signUp( size_t w_, size_t h_ )noexcept{ tprAssert( (w_<this->wLen) && (h_<this->hLen) ); size_t idx = h_ * this->wLen + w_; //--- tprAssert( (idx/BoolBitMap::BITS_PER_BYTE) < bitMap.size() ); uint8_t &bitRef = bitMap.at( idx/BoolBitMap::BITS_PER_BYTE ); bitRef = bitRef | static_cast<uint8_t>(1 << (idx%BoolBitMap::BITS_PER_BYTE)); } inline void signUp( size_t idx_ )noexcept{ tprAssert( idx_ < this->totalNum ); //--- tprAssert( (idx_/BoolBitMap::BITS_PER_BYTE) < bitMap.size() ); uint8_t &bitRef = bitMap.at( idx_/BoolBitMap::BITS_PER_BYTE ); bitRef = bitRef | static_cast<uint8_t>(1 << (idx_%BoolBitMap::BITS_PER_BYTE)); } inline bool check( size_t w_, size_t h_ )noexcept{ tprAssert( (w_<this->wLen) && (h_<this->hLen) ); size_t idx = h_ * this->wLen + w_; //--- tprAssert( (idx/BoolBitMap::BITS_PER_BYTE) < bitMap.size() ); const uint8_t &bitRef = bitMap.at( idx/BoolBitMap::BITS_PER_BYTE ); return ( ((bitRef>>(idx%BoolBitMap::BITS_PER_BYTE)) & 1)==1 ); } inline bool check( size_t idx_ )noexcept{ tprAssert( idx_ < this->totalNum ); //--- tprAssert( (idx_/BoolBitMap::BITS_PER_BYTE) < bitMap.size() ); const uint8_t &bitRef = bitMap.at( idx_/BoolBitMap::BITS_PER_BYTE ); return ( ((bitRef>>(idx_%BoolBitMap::BITS_PER_BYTE)) & 1)==1 ); } private: std::vector<uint8_t> bitMap {}; size_t wLen {}; size_t hLen {}; size_t totalNum {}; //======== static ========// static size_t BITS_PER_BYTE; }; #endif
turesnake/tprPixelGames
src/Engine/tools/MapCoord.h
/* * ====================== MapCoord.h ======================= * -- tpr -- * CREATE -- 2019.01.09 * MODIFY -- * ---------------------------------------------------------- * some kinds of pos: * FPos - float pos (pix) * DPos - double pos (pix) * PPos - pixel pos * MPos - mapEnt pos * FDPos - field pos * CPos - chunk pos * SPos - section pos (unimplement) * ---------------------------- */ #ifndef TPR_MAP_COORD_H #define TPR_MAP_COORD_H //--- glm - 0.9.9.5 --- #include "glm_no_warnings.h" //-------------------- CPP --------------------// #include <cmath> //-------------------- Engine --------------------// #include "tprAssert.h" #include "IntVec.h" #include "config.h" inline IntVec2 mpos_2_ppos( IntVec2 mpos_ ) noexcept { return (mpos_*PIXES_PER_MAPENT<>); } //-- 当 dpos 无限接近 mapent 边界时,这个返回值就会非常不精确... inline IntVec2 dpos_2_mpos( const glm::dvec2 &dpos_ ) noexcept { //-- double除法 double fx = dpos_.x / PIXES_PER_MAPENT_D; double fy = dpos_.y / PIXES_PER_MAPENT_D; //-- math.floor() return IntVec2{ static_cast<int>(floor(fx)), static_cast<int>(floor(fy)) }; } inline glm::dvec2 mpos_2_dpos( IntVec2 mpos_ ) noexcept { return glm::dvec2{ static_cast<double>(mpos_.x * PIXES_PER_MAPENT<>), static_cast<double>(mpos_.y * PIXES_PER_MAPENT<>) }; } inline glm::dvec2 mpos_2_midDPos( IntVec2 mpos_ ) noexcept { return glm::dvec2{ static_cast<double>(mpos_.x * PIXES_PER_MAPENT<> + HALF_PIXES_PER_MAPENT<>), static_cast<double>(mpos_.y * PIXES_PER_MAPENT<> + HALF_PIXES_PER_MAPENT<>) }; } /* =========================================================== * calc_fast_mpos_distance * ----------------------------------------------------------- * 计算两个 mpos 的距离(快速版,不开根号) * 和上一个函数并没有本质区别。 * 返回的结果,只是一个 “含糊的距离概念” [主要用来 生成 cell-noise] */ /* inline int calc_fast_mpos_distance( IntVec2 aMPos_, IntVec2 bMPos_ ) noexcept { IntVec2 off = aMPos_ - bMPos_; //-- 没有做 溢出检测... return (off.x*off.x + off.y*off.y); } */ #endif
turesnake/tprPixelGames
src/Engine/time/TimeCircle.h
/* * ========================= TimeBase.h ========================== * -- tpr -- * CREATE -- 2018.12.22 * MODIFY -- * ---------------------------------------------------------- * 定义一种 时间循环 * ---------------------------- */ #ifndef TPR_TIME_CIRCLE_H #define TPR_TIME_CIRCLE_H #include "TimeBase.h" //--- 管理一种 时间循环 ---// // 每 n 帧 算一次 循环 class TimeCircle{ public: TimeCircle( TimeBase &timerRef_, size_t frameNum_ ): timerRef(timerRef_), frameNum(frameNum_) {} //-- 返回当前 帧 在 时间循环中的 位置 -- inline size_t current()noexcept{ return (this->timerRef.get_frameNum() % this->frameNum); } private: TimeBase &timerRef; //- 绑定一个 全局 timer size_t frameNum; //- 一个circle 需要 多少 帧。 }; #endif
turesnake/tprPixelGames
src/Script/gameObjs/oth/GroundGo.h
<filename>src/Script/gameObjs/oth/GroundGo.h<gh_stars>100-1000 /* * ===================== GroundGo.h ========================== * -- tpr -- * CREATE -- 2019.08.28 * MODIFY -- * ---------------------------------------------------------- */ #ifndef TPR_GO_GROUND_GO_H #define TPR_GO_GROUND_GO_H //-------------------- Engine --------------------// #include "GameObj.h" #include "DyParam.h" namespace gameObjs{//------------- namespace gameObjs ---------------- class GroundGo{ public: static void init(GameObj &goRef_, const DyParam &dyParams_ ); private: //--- callback ---// static void OnRenderUpdate( GameObj &goRef_ ); static void OnActionSwitch( GameObj &goRef_, ActionSwitchType type_ ); }; }//------------- namespace gameObjs: end ---------------- #endif
turesnake/tprPixelGames
src/Engine/blueprint/PlotBlueprint.h
<reponame>turesnake/tprPixelGames /* * ======================= PlotBlueprint.h ======================= * -- tpr -- * CREATE -- 2019.12.02 * MODIFY -- * ---------------------------------------------------------- */ #ifndef TPR_PLOT_BLUE_PRINT_H #define TPR_PLOT_BLUE_PRINT_H #include "pch.h" //-------------------- CPP --------------------// #include <variant> //-------------------- Engine --------------------// #include "BlueprintVarType.h" #include "blueprintId.h" #include "GameObjType.h" #include "NineDirection.h" #include "BrokenLvl.h" #include "FloorGoType.h" #include "ID_Manager.h" #include "GoAssemblePlan.h" namespace blueprint {//------------------ namespace: blueprint start ---------------------// // 记录每个 mapent 上的数据,并不全,只有一部分, // 剩余的信息,要通过 varType 获得 class MapDataEnt{ public: MapDataEnt()=default; //------- vals -------// VariableTypeIdx varTypeIdx {}; IntVec2 mposOff {}; // based on left-bottom BrokenLvl brokenLvl {}; NineDirection direction {NineDirection::Center}; //- 角色 动画朝向 }; //- 一个实例,就是 1-frame png 数据,也就是一份 蓝图实例 class MapData{ public: std::vector<std::unique_ptr<MapDataEnt>> data {}; }; //- 确定一个 go 物种 的最基本数据 class GoSpec{ public: GoSpec()=default; //----- vals -----// goSpeciesId_t goSpeciesId {}; std::string afsName {}; // 允许为 "", 此时 animLabel == "" std::string animLabel {}; goLabelId_t goLabelId {}; bool isPlaceHolder {false}; // 单纯的占位元素,当从分配池中抽到 此类元素时,什么go也不生成 }; using varTypeDatas_PlotId_t = uint32_t; // 蓝图中,每种变量,对应的一组数据 // 数据不是单一的,可以是一个随机池,从中选取一种 class VarTypeDatas_Plot{ public: VarTypeDatas_Plot()=default; //----- set -----// inline void set_isAllInstanceUseSamePlan( bool b_ )noexcept{ this->isAllInstanceUseSamePlan = b_; } inline void insert_2_goSpecPool( std::unique_ptr<GoSpec> uptr_, size_t num_ )noexcept{ varTypeDatas_PlotId_t id = VarTypeDatas_Plot::id_manager.apply_a_u32_id();// 盲目分配id auto [insertIt, insertBool] = this->goSpecPool.emplace( id, std::move(uptr_) ); tprAssert( insertBool ); //-- this->randPool.insert( this->randPool.end(), num_, id ); } void init_check()noexcept; //----- get -----// inline bool get_isAllInstanceUseSamePlan()const noexcept{ return this->isAllInstanceUseSamePlan; } inline const GoSpec &apply_rand_goSpec( size_t uWeight_ )const noexcept{ varTypeDatas_PlotId_t id = this->randPool.at( (uWeight_ + 3556177) % this->randPool.size() ); return *(this->goSpecPool.at(id)); } private: std::vector<varTypeDatas_PlotId_t> randPool {}; // 随机抽取池 std::unordered_map<varTypeDatas_PlotId_t, std::unique_ptr<GoSpec>> goSpecPool {}; // 可有 1~n 种,禁止为 0 种 bool isAllInstanceUseSamePlan {}; // 是否 本类型的所有个体,共用一个 实例化对象 //======== static ========// static ID_Manager id_manager; }; // 地块级蓝图。最小级别的蓝图,只有 数 mapents 大 // class PlotBlueprint{ public: inline void insert_2_varTypeDatas( VariableTypeIdx typeIdx_, std::unique_ptr<VarTypeDatas_Plot> uptr_ )noexcept{ auto [insertIt1, insertBool1] = this->varTypeDatas.insert({ typeIdx_, std::move(uptr_) }); tprAssert( insertBool1 ); auto [insertIt2, insertBool2] = this->varTypes.insert( typeIdx_ ); tprAssert( insertBool2 ); } inline void set_sizeByMapEnt( IntVec2 val_ )noexcept{ this->sizeByMapEnt = val_; } inline void init_check()const noexcept{ tprAssert( !this->mapDatas.empty() ); tprAssert( !this->varTypes.empty() ); tprAssert( !this->varTypeDatas.empty() ); } //- 仅用于 读取 json数据 时 - inline std::vector<MapData> &getnc_mapDatasRef()noexcept{ return this->mapDatas; } inline const std::set<VariableTypeIdx> &get_varTypes()const noexcept{ return this->varTypes; } inline const MapData &apply_a_random_mapData( size_t uWeight_ )const noexcept{ return this->mapDatas.at( (uWeight_ + 1844477191) % this->mapDatas.size() ); } inline const VarTypeDatas_Plot *get_varTypeDataPtr_Plot( VariableTypeIdx type_ )const noexcept{ tprAssert( this->varTypeDatas.find(type_) != this->varTypeDatas.end() ); return this->varTypeDatas.at(type_).get(); } //===== static =====// static void init_for_static()noexcept; // MUST CALL IN MAIN !!! static plotBlueprintId_t init_new_plot( const std::string &plotName_, const std::string &plotLabel_ ); inline static PlotBlueprint &get_plotBlueprintRef( plotBlueprintId_t id_ )noexcept{ tprAssert( PlotBlueprint::plotUPtrs.find(id_) != PlotBlueprint::plotUPtrs.end() ); return *(PlotBlueprint::plotUPtrs.at(id_)); } // "_PLACE_HOLDER_", "_PLACE_HOLDER_" 为占位符 专用 inline static plotBlueprintId_t str_2_plotBlueprintId( const std::string &plotName_, const std::string &plotLabel_ )noexcept{ if( plotName_ == "_PLACE_HOLDER_" ){ tprAssert( plotLabel_ == "_PLACE_HOLDER_" ); return PlotBlueprint::placeHolderId; } tprAssert( PlotBlueprint::name_2_ids.find(plotName_) != PlotBlueprint::name_2_ids.end() ); const auto &innUMap = PlotBlueprint::name_2_ids.at( plotName_ ); tprAssert( innUMap.find(plotLabel_) != innUMap.end() ); return innUMap.at( plotLabel_ ); } inline static bool is_placeHolderId( plotBlueprintId_t id_ )noexcept{ return (id_ == PlotBlueprint::placeHolderId); } private: PlotBlueprint()=default; IntVec2 sizeByMapEnt {}; // plot 尺寸,以 mapent 为单位 不一定必须是 正方形 std::vector<MapData> mapDatas {}; // 若干帧,每一帧数据 就是一份 分配方案 std::set<VariableTypeIdx> varTypes {}; std::unordered_map<VariableTypeIdx, std::unique_ptr<VarTypeDatas_Plot>> varTypeDatas {}; // 类型数据 //======== static ========// static ID_Manager id_manager; static constexpr plotBlueprintId_t placeHolderId { static_cast<plotBlueprintId_t>(-1) }; // 占位符专用 // 两层索引:plotName, plotLabel static std::unordered_map<std::string, std::unordered_map<std::string, plotBlueprintId_t>> name_2_ids; // 索引表 static std::unordered_map<plotBlueprintId_t, std::unique_ptr<PlotBlueprint>> plotUPtrs; // 真实资源 }; void parse_plotJsonFiles(); }//--------------------- namespace: blueprint end ------------------------// #endif
turesnake/tprPixelGames
src/Engine/shaderProgram/ShaderProgram.h
/* * ========================= ShaderProgram.h ========================== * -- tpr -- * CREATE -- 2018.11.21 * MODIFY -- * ---------------------------------------------------------- * 着色器程序 类 * ---------------------------- */ #ifndef TPR_SHADER_PROGRAM_H #define TPR_SHADER_PROGRAM_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> #include <memory> //-------------------- Engine --------------------// #include "UniformBlockObj.h" #include "tprAssert.h" class ShaderProgram{ public: ShaderProgram() = default; //--- init ---// void init( const std::string &lpathVs_, const std::string &lpathFs_ ); //-- 从 着色器程序中 获得 目标变量的 地址 inline void add_new_uniform( const std::string &name_ )noexcept{ tprAssert( this->is_shaderProgram_set ); auto [insertIt, insertBool] = uniforms.emplace( name_, glGetUniformLocation(this->shaderProgram, name_.c_str()) ); tprAssert( insertBool ); } inline GLint get_uniform_location( const std::string &name_ )noexcept{ tprAssert( this->uniforms.find(name_) != this->uniforms.end() ); return this->uniforms.at(name_); } inline void use_program()noexcept{ if( this->shaderProgram == shaderProgram_current ){ return; } glUseProgram( this->shaderProgram ); shaderProgram_current = this->shaderProgram; } //-- 将 3个矩阵 的值 传输到 着色器程序。 inline void send_mat4_model_2_shader( const glm::mat4 &m_ )noexcept{ this->use_program(); glUniformMatrix4fv( this->get_uniform_location( "model" ), 1, GL_FALSE, glm::value_ptr(m_) ); } inline GLuint get_shaderProgramObj()const noexcept{ return this->shaderProgram; } private: void compile( GLuint shaderObj_, const std::string &sbuf_ ); //======== vals ========// GLuint shaderProgram {0}; //-- 着色器程序中的 uniform 变量们 std::unordered_map<std::string, GLint> uniforms {}; //======== flags ========// bool is_shaderProgram_set {false}; //======== static ========// static GLuint shaderProgram_current; //-- 当前被使用的 shaderProgram }; #endif
turesnake/tprPixelGames
src/Engine/resource/esrc_gameSeed.h
<gh_stars>100-1000 /* * ========================= esrc_gameSeed.h ========================== * -- tpr -- * CREATE -- 2019.04.19 * MODIFY -- * ---------------------------------------------------------- */ #ifndef TPR_ESRC_GAME_SEED_H #define TPR_ESRC_GAME_SEED_H //-------------------- Engine --------------------// #include "GameSeed.h" namespace esrc {//------------------ namespace: esrc -------------------------// void init_gameSeed(); GameSeed &get_gameSeed(); }//---------------------- namespace: esrc -------------------------// #endif
turesnake/tprPixelGames
src/Engine/input/KeyBoard.h
<gh_stars>100-1000 /* * ========================= KeyBoard.h ========================== * -- tpr -- * CREATE -- 2019.02.13 * MODIFY -- * ---------------------------------------------------------- */ #ifndef TPR_KEYBOARD_H #define TPR_KEYBOARD_H //=== *** glad FIRST, glfw SECEND *** === // Don't include glfw3.h ALONE!!! #include<glad/glad.h> #include<GLFW/glfw3.h> //-------------------- CPP --------------------// #include <string> #include <set> //-------------------- Engine --------------------// #include "tprAssert.h" class KeyBoard{ public: enum class Key : int{ NOT_CARE = -2, // glfw 有效的键,但不在本游戏关心范围内,一律归为本类型 //-- UNKNOWN = GLFW_KEY_UNKNOWN, // -1 //--- NIL = 0, //- null //--- SPACE = GLFW_KEY_SPACE, APOSTROPHE = GLFW_KEY_APOSTROPHE, /* ' */ COMMA = GLFW_KEY_COMMA, /* , */ MINUS = GLFW_KEY_MINUS, /* - */ PERIOD = GLFW_KEY_PERIOD, /* . */ SLASH = GLFW_KEY_SLASH, /* / */ SEMICOLON = GLFW_KEY_SEMICOLON, /* ; */ EQUAL = GLFW_KEY_EQUAL, /* = */ // num NUM_0 = GLFW_KEY_0, NUM_1 = GLFW_KEY_1, NUM_2 = GLFW_KEY_2, NUM_3 = GLFW_KEY_3, NUM_4 = GLFW_KEY_4, NUM_5 = GLFW_KEY_5, NUM_6 = GLFW_KEY_6, NUM_7 = GLFW_KEY_7, NUM_8 = GLFW_KEY_8, NUM_9 = GLFW_KEY_9, // keypad KP_0 = GLFW_KEY_KP_0, KP_1 = GLFW_KEY_KP_1, KP_2 = GLFW_KEY_KP_2, KP_3 = GLFW_KEY_KP_3, KP_4 = GLFW_KEY_KP_4, KP_5 = GLFW_KEY_KP_5, KP_6 = GLFW_KEY_KP_6, KP_7 = GLFW_KEY_KP_7, KP_8 = GLFW_KEY_KP_8, KP_9 = GLFW_KEY_KP_9, KP_DIVIDE = GLFW_KEY_KP_DIVIDE, KP_MULTIPLY = GLFW_KEY_KP_MULTIPLY, KP_SUBTRACT = GLFW_KEY_KP_SUBTRACT, KP_ADD = GLFW_KEY_KP_ADD, KP_DECIMAL = GLFW_KEY_KP_DECIMAL, KP_EQUAL = GLFW_KEY_KP_EQUAL, KP_ENTER = GLFW_KEY_KP_ENTER, //-------- A = GLFW_KEY_A, B = GLFW_KEY_B, C = GLFW_KEY_C, D = GLFW_KEY_D, E = GLFW_KEY_E, F = GLFW_KEY_F, G = GLFW_KEY_G, H = GLFW_KEY_H, I = GLFW_KEY_I, J = GLFW_KEY_J, K = GLFW_KEY_K, L = GLFW_KEY_L, M = GLFW_KEY_M, N = GLFW_KEY_N, O = GLFW_KEY_O, P = GLFW_KEY_P, Q = GLFW_KEY_Q, R = GLFW_KEY_R, S = GLFW_KEY_S, T = GLFW_KEY_T, U = GLFW_KEY_U, V = GLFW_KEY_V, W = GLFW_KEY_W, X = GLFW_KEY_X, Y = GLFW_KEY_Y, Z = GLFW_KEY_Z, //-------- LEFT_BRACKET = GLFW_KEY_LEFT_BRACKET, /* [ */ BACKSLASH = GLFW_KEY_BACKSLASH, /* \ */ RIGHT_BRACKET = GLFW_KEY_RIGHT_BRACKET, /* ] */ GRAVE_ACCENT = GLFW_KEY_GRAVE_ACCENT, /* ` */ //-------- ESCAPE = GLFW_KEY_ESCAPE, ENTER = GLFW_KEY_ENTER, TAB = GLFW_KEY_TAB, BACKSPACE = GLFW_KEY_BACKSPACE, INSERT = GLFW_KEY_INSERT, DELETE_ = GLFW_KEY_DELETE, //- DELETE 是关键词,有冲突 RIGHT = GLFW_KEY_RIGHT, LEFT = GLFW_KEY_LEFT, DOWN = GLFW_KEY_DOWN, UP = GLFW_KEY_UP, PAGE_UP = GLFW_KEY_PAGE_UP, PAGE_DOWN = GLFW_KEY_PAGE_DOWN, HOME = GLFW_KEY_HOME, END = GLFW_KEY_END, CAPS_LOCK = GLFW_KEY_CAPS_LOCK, SCROLL_LOCK = GLFW_KEY_SCROLL_LOCK, NUM_LOCK = GLFW_KEY_NUM_LOCK, PRINT_SCREEN = GLFW_KEY_PRINT_SCREEN, PAUSE = GLFW_KEY_PAUSE, //-------- F1 = GLFW_KEY_F1, F2 = GLFW_KEY_F2, F3 = GLFW_KEY_F3, F4 = GLFW_KEY_F4, F5 = GLFW_KEY_F5, F6 = GLFW_KEY_F6, F7 = GLFW_KEY_F7, F8 = GLFW_KEY_F8, F9 = GLFW_KEY_F9, F10 = GLFW_KEY_F10, F11 = GLFW_KEY_F11, F12 = GLFW_KEY_F12, //-------- LEFT_SHIFT = GLFW_KEY_LEFT_SHIFT, LEFT_CONTROL = GLFW_KEY_LEFT_CONTROL, LEFT_ALT = GLFW_KEY_LEFT_ALT, LEFT_SUPER = GLFW_KEY_LEFT_SUPER, RIGHT_SHIFT = GLFW_KEY_RIGHT_SHIFT, RIGHT_CONTROL = GLFW_KEY_RIGHT_CONTROL, RIGHT_ALT = GLFW_KEY_RIGHT_ALT, RIGHT_SUPER = GLFW_KEY_RIGHT_SUPER, MENU = GLFW_KEY_MENU, //-------- }; //========== Selfs ==========// KeyBoard()=default; inline bool get_isAnyKeyPress()const noexcept{ return !this->pressedKeys.empty(); } inline bool get_key( KeyBoard::Key key_ )const noexcept{ return (this->pressedKeys.find(key_) != this->pressedKeys.end()); } inline void insert_key( KeyBoard::Key key_ )noexcept{ auto [insertIt, insertBool] = this->pressedKeys.insert(key_); tprAssert( insertBool ); // Must success } inline void erase_key( KeyBoard::Key key_ )noexcept{ size_t eraseNum = this->pressedKeys.erase( key_ ); tprAssert( eraseNum == 1 ); // Must have } inline const std::set<KeyBoard::Key> &get_pressedKeysRef()const noexcept{ return this->pressedKeys; } private: //========== Selfs ==========// std::set<KeyBoard::Key> pressedKeys {}; // 当前正被按下的 键盘按键 }; std::string keyBoardKey_2_str( KeyBoard::Key kb_ )noexcept; // 仅用于,从 glfw 函数中获得的 key 值 inline KeyBoard::Key glfwKey_2_KeyBoardKey( int glfwKey_ )noexcept{ switch (glfwKey_){ case GLFW_KEY_UNKNOWN: return KeyBoard::Key::UNKNOWN; case GLFW_KEY_SPACE: return KeyBoard::Key::SPACE; case GLFW_KEY_APOSTROPHE: return KeyBoard::Key::APOSTROPHE; case GLFW_KEY_COMMA: return KeyBoard::Key::COMMA; case GLFW_KEY_MINUS: return KeyBoard::Key::MINUS; case GLFW_KEY_PERIOD: return KeyBoard::Key::PERIOD; case GLFW_KEY_SLASH: return KeyBoard::Key::SLASH; case GLFW_KEY_SEMICOLON: return KeyBoard::Key::SEMICOLON; case GLFW_KEY_EQUAL: return KeyBoard::Key::EQUAL; case GLFW_KEY_0: return KeyBoard::Key::NUM_0; case GLFW_KEY_1: return KeyBoard::Key::NUM_1; case GLFW_KEY_2: return KeyBoard::Key::NUM_2; case GLFW_KEY_3: return KeyBoard::Key::NUM_3; case GLFW_KEY_4: return KeyBoard::Key::NUM_4; case GLFW_KEY_5: return KeyBoard::Key::NUM_5; case GLFW_KEY_6: return KeyBoard::Key::NUM_6; case GLFW_KEY_7: return KeyBoard::Key::NUM_7; case GLFW_KEY_8: return KeyBoard::Key::NUM_8; case GLFW_KEY_9: return KeyBoard::Key::NUM_9; case GLFW_KEY_KP_0: return KeyBoard::Key::KP_0; case GLFW_KEY_KP_1: return KeyBoard::Key::KP_1; case GLFW_KEY_KP_2: return KeyBoard::Key::KP_2; case GLFW_KEY_KP_3: return KeyBoard::Key::KP_3; case GLFW_KEY_KP_4: return KeyBoard::Key::KP_4; case GLFW_KEY_KP_5: return KeyBoard::Key::KP_5; case GLFW_KEY_KP_6: return KeyBoard::Key::KP_6; case GLFW_KEY_KP_7: return KeyBoard::Key::KP_7; case GLFW_KEY_KP_8: return KeyBoard::Key::KP_8; case GLFW_KEY_KP_9: return KeyBoard::Key::KP_9; case GLFW_KEY_KP_DIVIDE: return KeyBoard::Key::KP_DIVIDE; case GLFW_KEY_KP_MULTIPLY: return KeyBoard::Key::KP_MULTIPLY; case GLFW_KEY_KP_SUBTRACT: return KeyBoard::Key::KP_SUBTRACT; case GLFW_KEY_KP_ADD: return KeyBoard::Key::KP_ADD; case GLFW_KEY_KP_DECIMAL: return KeyBoard::Key::KP_DECIMAL; case GLFW_KEY_KP_EQUAL: return KeyBoard::Key::KP_EQUAL; case GLFW_KEY_KP_ENTER: return KeyBoard::Key::KP_ENTER; case GLFW_KEY_A: return KeyBoard::Key::A; case GLFW_KEY_B: return KeyBoard::Key::B; case GLFW_KEY_C: return KeyBoard::Key::C; case GLFW_KEY_D: return KeyBoard::Key::D; case GLFW_KEY_E: return KeyBoard::Key::E; case GLFW_KEY_F: return KeyBoard::Key::F; case GLFW_KEY_G: return KeyBoard::Key::G; case GLFW_KEY_H: return KeyBoard::Key::H; case GLFW_KEY_I: return KeyBoard::Key::I; case GLFW_KEY_J: return KeyBoard::Key::J; case GLFW_KEY_K: return KeyBoard::Key::K; case GLFW_KEY_L: return KeyBoard::Key::L; case GLFW_KEY_M: return KeyBoard::Key::M; case GLFW_KEY_N: return KeyBoard::Key::N; case GLFW_KEY_O: return KeyBoard::Key::O; case GLFW_KEY_P: return KeyBoard::Key::P; case GLFW_KEY_Q: return KeyBoard::Key::Q; case GLFW_KEY_R: return KeyBoard::Key::R; case GLFW_KEY_S: return KeyBoard::Key::S; case GLFW_KEY_T: return KeyBoard::Key::T; case GLFW_KEY_U: return KeyBoard::Key::U; case GLFW_KEY_V: return KeyBoard::Key::V; case GLFW_KEY_W: return KeyBoard::Key::W; case GLFW_KEY_X: return KeyBoard::Key::X; case GLFW_KEY_Y: return KeyBoard::Key::Y; case GLFW_KEY_Z: return KeyBoard::Key::Z; case GLFW_KEY_LEFT_BRACKET: return KeyBoard::Key::LEFT_BRACKET; case GLFW_KEY_BACKSLASH: return KeyBoard::Key::BACKSLASH; case GLFW_KEY_RIGHT_BRACKET: return KeyBoard::Key::RIGHT_BRACKET; case GLFW_KEY_GRAVE_ACCENT: return KeyBoard::Key::GRAVE_ACCENT; case GLFW_KEY_ESCAPE: return KeyBoard::Key::ESCAPE; // 不支持游戏按键映射 case GLFW_KEY_ENTER: return KeyBoard::Key::ENTER; case GLFW_KEY_TAB: return KeyBoard::Key::TAB; case GLFW_KEY_BACKSPACE: return KeyBoard::Key::BACKSPACE; case GLFW_KEY_INSERT: return KeyBoard::Key::INSERT; case GLFW_KEY_DELETE: return KeyBoard::Key::DELETE_; case GLFW_KEY_RIGHT: return KeyBoard::Key::RIGHT; case GLFW_KEY_LEFT: return KeyBoard::Key::LEFT; case GLFW_KEY_DOWN: return KeyBoard::Key::DOWN; case GLFW_KEY_UP: return KeyBoard::Key::UP; case GLFW_KEY_PAGE_UP: return KeyBoard::Key::PAGE_UP; case GLFW_KEY_PAGE_DOWN: return KeyBoard::Key::PAGE_DOWN; case GLFW_KEY_HOME: return KeyBoard::Key::HOME; case GLFW_KEY_END: return KeyBoard::Key::END; //case GLFW_KEY_CAPS_LOCK: return KeyBoard::Key::CAPS_LOCK; // 不支持游戏按键映射 //case GLFW_KEY_SCROLL_LOCK: return KeyBoard::Key::SCROLL_LOCK; // 不支持游戏按键映射 //case GLFW_KEY_NUM_LOCK: return KeyBoard::Key::NUM_LOCK; // 不支持游戏按键映射 //case GLFW_KEY_PRINT_SCREEN: return KeyBoard::Key::PRINT_SCREEN;// 不支持游戏按键映射 //case GLFW_KEY_PAUSE: return KeyBoard::Key::PAUSE; // 不支持游戏按键映射 case GLFW_KEY_F1: return KeyBoard::Key::F1; case GLFW_KEY_F2: return KeyBoard::Key::F2; case GLFW_KEY_F3: return KeyBoard::Key::F3; case GLFW_KEY_F4: return KeyBoard::Key::F4; case GLFW_KEY_F5: return KeyBoard::Key::F5; case GLFW_KEY_F6: return KeyBoard::Key::F6; case GLFW_KEY_F7: return KeyBoard::Key::F7; case GLFW_KEY_F8: return KeyBoard::Key::F8; case GLFW_KEY_F9: return KeyBoard::Key::F9; case GLFW_KEY_F10: return KeyBoard::Key::F10; case GLFW_KEY_F11: return KeyBoard::Key::F11; case GLFW_KEY_F12: return KeyBoard::Key::F12; case GLFW_KEY_LEFT_SHIFT: return KeyBoard::Key::LEFT_SHIFT; case GLFW_KEY_LEFT_CONTROL: return KeyBoard::Key::LEFT_CONTROL; case GLFW_KEY_LEFT_ALT: return KeyBoard::Key::LEFT_ALT; case GLFW_KEY_LEFT_SUPER: return KeyBoard::Key::LEFT_SUPER; case GLFW_KEY_RIGHT_SHIFT: return KeyBoard::Key::RIGHT_SHIFT; case GLFW_KEY_RIGHT_CONTROL: return KeyBoard::Key::RIGHT_CONTROL; case GLFW_KEY_RIGHT_ALT: return KeyBoard::Key::RIGHT_ALT; case GLFW_KEY_RIGHT_SUPER: return KeyBoard::Key::RIGHT_SUPER; case GLFW_KEY_MENU: return KeyBoard::Key::MENU; case 0: // 不存在 0 值 tprAssert(0); return KeyBoard::Key::NIL; // never reach default: // glfw 认可的键,但本游戏不关心 return KeyBoard::Key::NOT_CARE; } } #endif
turesnake/tprPixelGames
src/Engine/gameObj/BrokenLvl.h
<filename>src/Engine/gameObj/BrokenLvl.h<gh_stars>100-1000 /* * ======================= BrokenLvl.h ========================== * -- tpr -- * CREATE -- 2019.12.02 * MODIFY -- * ---------------------------------------------------------- */ #ifndef TPR_BROKEN_LEVEL_H #define TPR_BROKEN_LEVEL_H //-------------------- CPP --------------------// #include <string> //-------------------- Engine --------------------// #include "tprAssert.h" // go 的 破损等级 // 会被记录在 蓝图 .D.png 数据中,代表每个 mp-go 的健全状态 // 比如,石头有几种破损状态 // --- // 每种 go 自身的 HealthState 划分,是完全自定义的,可能不会用完全部的值 enum class BrokenLvl{ Lvl_0, // 最完好,最健全的状态 Lvl_1, // 往下依次变得破损 Lvl_2, Lvl_3, Lvl_4 }; std::string brokenLvl_2_str( BrokenLvl bl_ )noexcept; BrokenLvl str_2_brokenLvl( const std::string &str_ )noexcept; inline BrokenLvl int_2_brokenLvl( int val_ )noexcept{ switch (val_){ case 0: return BrokenLvl::Lvl_0; case 1: return BrokenLvl::Lvl_1; case 2: return BrokenLvl::Lvl_2; case 3: return BrokenLvl::Lvl_3; case 4: return BrokenLvl::Lvl_4; default: tprAssert(0); return BrokenLvl::Lvl_0; } } #endif
turesnake/tprPixelGames
src/Script/gameObjs/bioSoup/bioSoupInn.h
<filename>src/Script/gameObjs/bioSoup/bioSoupInn.h /* * ====================== bioSoupInn.h ======================= * -- tpr -- * CREATE -- 2020.03.05 * MODIFY -- * ---------------------------------------------------------- * only included by BioSoup.cpp */ #ifndef TPR_BIO_SOUP_INN_H #define TPR_BIO_SOUP_INN_H namespace gameObjs::bioSoup {//------------- namespace gameObjs::bioSoup ---------------- //void init_for_particle(); }//------------- namespace gameObjs::bioSoup: end ---------------- #endif
turesnake/tprPixelGames
src/Engine/gameObj/goDataForCreate/GoSpecFromJson.h
/* * ====================== GoSpecFromJson.h ========================== * -- tpr -- * CREATE -- 2019.10.11 * MODIFY -- * ---------------------------------------------------------- */ #ifndef TPR_GO_SPEC_FROM_JSON_H #define TPR_GO_SPEC_FROM_JSON_H #include "pch.h" //-------------------- Engine --------------------// #include "GameObjType.h" #include "Move.h" #include "PubBinary2.h" #include "GoAltiRange.h" #include "GoAssemblePlan.h" #include "AnimActionEName.h" class GameObj; // 从 go.json 文件中都取得数据,被存储为 此格式 class GoSpecFromJson{ public: //========== Nested ==========// class MoveStateTable; //========== Self ==========// inline std::unordered_set<std::string> *get_afsNamesPtr()noexcept{ return &(this->afsNames); } inline void insert_2_ExtraPassableDogoSpeciesIds( const std::string &name_ )noexcept{ std::hash<std::string> hasher; goSpeciesId_t id = static_cast<goSpeciesId_t>( hasher(name_) ); // size_t -> uint64_t this->extraPassableDogoSpeciesIds.insert( id ); } inline void insert_2_lAltiRanges( GoAltiRangeLabel label_, GoAltiRange val_ )noexcept{ auto [insertIt, insertBool] = this->lAltiRanges.emplace( label_, val_ ); tprAssert( insertBool ); } inline GoAltiRange get_lAltiRange( GoAltiRangeLabel label_ )const noexcept{ tprAssert( this->lAltiRanges.find(label_) != this->lAltiRanges.end() ); return this->lAltiRanges.at( label_ ); } void init_check()noexcept; //======== vals ========// std::string goSpeciesName {}; goSpeciesId_t speciesId {}; GameObjFamily family {}; GameObjState state {}; GameObjMoveState moveState {}; MoveType moveType {}; //----- bool -----// bool isMoveCollide {}; bool isDoPass {}; bool isBePass {}; //----- numbers -----// SpeedLevel moveSpeedLvl {}; double alti {}; double weight {}; //... PubBinary2 pubBinary {}; std::unique_ptr<GoAssemblePlanSet> goAssemblePlanSetUPtr {nullptr}; // 数据存储地 std::unique_ptr<MoveStateTable> moveStateTableUPtr {nullptr}; //======== static ========// static void assemble_2_newGo( goSpeciesId_t specID_, GameObj &goRef_ ); static void check_all_extraPassableDogoSpeciesIds()noexcept; inline static GoSpecFromJson &create_new_goSpecFromJson( const std::string &name_ )noexcept{ std::hash<std::string> hasher; goSpeciesId_t id = static_cast<goSpeciesId_t>( hasher(name_) ); // size_t -> uint64_t std::unique_ptr<GoSpecFromJson> uptr ( new GoSpecFromJson() ); // can't use std::make_unique auto [insertIt, insertBool] = GoSpecFromJson::dataUPtrs.emplace( id, std::move(uptr) ); tprAssert( insertBool ); GoSpecFromJson &ref = *(insertIt->second); //-- ref.goSpeciesName = name_; ref.speciesId = id; GoSpecFromJson::insert_2_goSpeciesIds_names_containers( id, name_ ); //-- return ref; } inline static GoSpecFromJson &getnc_goSpecFromJsonRef( goSpeciesId_t id_ )noexcept{ tprAssert( GoSpecFromJson::dataUPtrs.find(id_) != GoSpecFromJson::dataUPtrs.end() ); return *(GoSpecFromJson::dataUPtrs.at(id_)); } // support multi-thread inline static const GoSpecFromJson &get_goSpecFromJsonRef( goSpeciesId_t id_ )noexcept{ tprAssert( GoSpecFromJson::dataUPtrs.find(id_) != GoSpecFromJson::dataUPtrs.end() ); return *(GoSpecFromJson::dataUPtrs.at(id_)); } inline static bool is_find_in_afsNames( goSpeciesId_t id_, const std::string &name_ )noexcept{ const auto &c = GoSpecFromJson::get_goSpecFromJsonRef(id_); return (c.afsNames.find(name_) != c.afsNames.end()); } inline static goSpeciesId_t str_2_goSpeciesId( const std::string &name_ ){ tprAssert( GoSpecFromJson::names_2_ids.find(name_) != GoSpecFromJson::names_2_ids.end() ); return GoSpecFromJson::names_2_ids.at(name_); } inline static const std::string &goSpeciesId_2_name( goSpeciesId_t id_ )noexcept{ tprAssert( GoSpecFromJson::ids_2_names.find(id_) != GoSpecFromJson::ids_2_names.end() ); return GoSpecFromJson::ids_2_names.at(id_); } inline static bool find_from_initFuncs( goSpeciesId_t goSpeciesId_ ){ return ( GoSpecFromJson::initFuncs.find(goSpeciesId_) != GoSpecFromJson::initFuncs.end()); } inline static void call_initFunc( goSpeciesId_t id_, GameObj &goRef_, const DyParam &dyParams_ ){ tprAssert( GoSpecFromJson::find_from_initFuncs(id_) ); GoSpecFromJson::initFuncs.at(id_)( goRef_, dyParams_ ); } inline static void insert_2_initFuncs( const std::string &goTypeName_, const F_GO_INIT &functor_ ){ goSpeciesId_t id = GoSpecFromJson::str_2_goSpeciesId( goTypeName_ ); auto [insertIt, insertBool] = GoSpecFromJson::initFuncs.emplace( id, functor_ ); tprAssert( insertBool ); } private: GoSpecFromJson()=default; inline static void insert_2_goSpeciesIds_names_containers( goSpeciesId_t id_, const std::string &name_ ){ auto out1 = GoSpecFromJson::ids_2_names.emplace( id_, name_ ); auto out2 = GoSpecFromJson::names_2_ids.emplace( name_, id_ ); tprAssert( out1.second ); tprAssert( out2.second ); } //======== vals ========// std::unordered_set<std::string> afsNames {}; std::unordered_map<GoAltiRangeLabel, GoAltiRange> lAltiRanges {}; //-- 当 isBePass == false 时,允许一组 特殊的 dogo,可以穿透本 bego // 正式使用时,只提供 只读指针 std::set<goSpeciesId_t> extraPassableDogoSpeciesIds {}; //======== static ========// // 资源持续整个游戏生命期,不用释放 static std::unordered_map<goSpeciesId_t, std::unique_ptr<GoSpecFromJson>> 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; }; class GoSpecFromJson::MoveStateTable{ public: MoveStateTable()=default; void init_check( const GoSpecFromJson *goSpecFromJsonPtr_ )noexcept; //--- vals ---// SpeedLevel minLvl {}; // include SpeedLevel maxLvl {}; // include std::map<SpeedLevel, std::pair<AnimActionEName,int>> table {}; // speedLvl, actionEName, timeStepOff }; namespace json{//------------- namespace json ---------------- void parse_goJsonFile(); }//------------- namespace json: end ---------------- #endif
turesnake/tprPixelGames
src/Engine/blueprint/VillageBlueprint.h
<filename>src/Engine/blueprint/VillageBlueprint.h /* * ======================= VillageBlueprint.h ======================= * -- tpr -- * CREATE -- 2019.12.02 * MODIFY -- * ---------------------------------------------------------- */ #ifndef TPR_VILLAGE_BLUE_PRINT_H #define TPR_VILLAGE_BLUE_PRINT_H #include "pch.h" //-------------------- Engine --------------------// #include "BlueprintVarType.h" #include "GameObjType.h" #include "NineDirection.h" #include "BrokenLvl.h" #include "YardBlueprint.h" namespace blueprint {//------------------ namespace: blueprint start ---------------------// class VarTypeDatas_Village{ public: VarTypeDatas_Village()=default; //----- set -----// inline void set_isAllInstanceUseSamePlan( bool b_ )noexcept{ this->isAllInstanceUseSamePlan = b_; } inline void set_isRoad( bool b_ )noexcept{ this->isRoad = b_; } inline void insert_2_getYardId_functors( YardBlueprintSet::F_getYardId f_, size_t num_ )noexcept{ this->getYardId_functors.insert( this->getYardId_functors.end(), num_, f_ ); // copy } void init_check()noexcept; //----- get -----// inline bool get_isRoad()const noexcept{ return this->isRoad; } inline bool get_isAllInstanceUseSamePlan()const noexcept{ return this->isAllInstanceUseSamePlan; } inline std::optional<yardBlueprintId_t> apply_rand_yardBlueprintId( size_t uWeight_, NineDirection yardDir_ )const noexcept{ size_t idx = (uWeight_ + 1076173) % this->getYardId_functors.size(); return this->getYardId_functors.at(idx)( yardDir_ ); } private: // 不再直接存储 yardId, 而是存储一组 函数指针,在运行时,通过参数传入 yardDir, 再找出 yardId std::vector<YardBlueprintSet::F_getYardId> getYardId_functors {}; bool isAllInstanceUseSamePlan {}; // 是否 本类型的所有个体,共用一个 实例化对象 bool isRoad {}; // 本变量是否为一个 道路单位 }; // 村级蓝图。最大级别的蓝图。 一个 section/ecoobj,分配一个 村级蓝图。 class VillageBlueprint{ public: inline void insert_2_varTypeDatas( VariableTypeIdx typeIdx_, std::unique_ptr<VarTypeDatas_Village> uptr_ )noexcept{ auto [insertIt1, insertBool1] = this->varTypeDatas.insert({ typeIdx_, std::move(uptr_) }); tprAssert( insertBool1 ); auto [insertIt2, insertBool2] = this->varTypes.insert( typeIdx_ ); tprAssert( insertBool2 ); } inline void init_check()const noexcept{ tprAssert( !this->mapDatas.empty() ); tprAssert( !this->varTypeDatas.empty() ); } //- 仅用于 读取 json数据 时 - inline std::vector<MapData> &getnc_mapDatasRef()noexcept{ return this->mapDatas; } inline const std::set<VariableTypeIdx> &get_varTypes()const noexcept{ return this->varTypes; } inline const MapData &apply_a_random_mapData( size_t uWeight_ )const noexcept{ return this->mapDatas.at( (uWeight_ + 3731577) % this->mapDatas.size() ); } inline const VarTypeDatas_Village *get_varTypeDataPtr_Village( VariableTypeIdx type_ )const noexcept{ tprAssert( this->varTypeDatas.find(type_) != this->varTypeDatas.end() ); return this->varTypeDatas.at(type_).get(); } //===== static =====// static void init_for_static()noexcept;// MUST CALL IN MAIN !!! static villageBlueprintId_t init_new_village( const std::string &name_ ); inline static VillageBlueprint &get_villageBlueprintRef( villageBlueprintId_t id_ )noexcept{ tprAssert( VillageBlueprint::villageUPtrs.find(id_) != VillageBlueprint::villageUPtrs.end() ); return *(VillageBlueprint::villageUPtrs.at(id_)); } inline static villageBlueprintId_t str_2_villageBlueprintId( const std::string &name_ )noexcept{ villageBlueprintId_t id = VillageBlueprint::hasher(name_); tprAssert( VillageBlueprint::villageIds.find(id) != VillageBlueprint::villageIds.end() ); return id; } private: VillageBlueprint()=default; std::vector<MapData> mapDatas {}; // 若干帧,每一帧数据 就是一份 分配方案 std::set<VariableTypeIdx> varTypes {}; std::unordered_map<VariableTypeIdx, std::unique_ptr<VarTypeDatas_Village>> varTypeDatas {}; // 类型数据 //===== static =====// static std::unordered_set<villageBlueprintId_t> villageIds; // 记录已被存储的 ids static std::hash<std::string> hasher; static std::unordered_map<villageBlueprintId_t, std::unique_ptr<VillageBlueprint>> villageUPtrs; // 真实资源 }; void parse_villageJsonFiles(); }//--------------------- namespace: blueprint end ------------------------// #endif
turesnake/tprPixelGames
src/Engine/animFrameSet/AnimActionEName.h
/* * ======================== AnimActionEName.h ========================== * -- tpr -- * CREATE -- 2020.01.16 * MODIFY -- * ---------------------------------------------------------- */ #ifndef TPR_ANIM_ACTION_E_NAME_H #define TPR_ANIM_ACTION_E_NAME_H //------------------- CPP --------------------// #include <string> // animaction name // --- // 代替 std::string, 提高运行时效率 // 缺点: 随着游戏内容的膨胀,会有越来越多的 元素加入进来。 // 每一次都会影响本 enum h文件 // 从而需要重编译 enum class AnimActionEName{ Idle, Walk, Run, Fly, Wind, Burn, // fire Rise, // bioSoup.particle //-- playerGoCircle -- SelfRotate, //--- UI-go 临时使用的 几个值 -- New, Data, Pointer, //... }; AnimActionEName str_2_animActionEName( const std::string &str_ )noexcept; std::string animActionEName_2_str( AnimActionEName a_ )noexcept; #endif
turesnake/tprPixelGames
src/Engine/resource/esrc_renderPool.h
<reponame>turesnake/tprPixelGames /* * ========================= esrc_renderPool.h ========================== * -- tpr -- * CREATE -- 2019.04.19 * MODIFY -- * ---------------------------------------------------------- */ #ifndef TPR_ESRC_RENDER_POOL_H #define TPR_ESRC_RENDER_POOL_H //-------------------- Engine --------------------// #include "RenderPool.h" #include "GroundRenderPool.h" namespace esrc {//------------------ namespace: esrc -------------------------// //-- Must after esrc::init_colorTableSet !!! void init_renderPools()noexcept; void debug_for_renderPools()noexcept; RenderPool &get_renderPool( RenderPoolType type_ )noexcept; GroundRenderPool &get_groundRenderPool()noexcept; void clear_all_renderPool()noexcept; }//---------------------- namespace: esrc -------------------------// #endif
turesnake/tprPixelGames
src/Engine/resource/esrc_time.h
/* * ========================= esrc_time.h ========================== * -- tpr -- * CREATE -- 2019.04.19 * MODIFY -- * ---------------------------------------------------------- */ #ifndef TPR_ESRC_TIME_H #define TPR_ESRC_TIME_H //-------------------- Engine --------------------// #include "TimeBase.h" #include "TimeCircle.h" #include "WindClock.h" namespace esrc {//------------------ namespace: esrc -------------------------// void init_time()noexcept; TimeBase &get_timer()noexcept; TimeCircle &get_logicTimeCircle()noexcept; WindClock &get_windClock()noexcept; }//---------------------- namespace: esrc -------------------------// #endif
turesnake/tprPixelGames
src/Engine/blueprint/blueprintId.h
/* * ===================== blueprintId.h ======================= * -- tpr -- * CREATE -- 2019.12.05 * MODIFY -- * ---------------------------------------------------------- */ #ifndef TPR_BLUE_PRINT_ID_H #define TPR_BLUE_PRINT_ID_H //------------------- CPP --------------------// #include <cstdint> // uint8_t namespace blueprint {//------------------ namespace: blueprint start ---------------------// using plotBlueprintId_t = uint32_t; using yardBlueprintId_t = uint32_t; using villageBlueprintId_t = size_t; }//--------------------- namespace: blueprint end ------------------------// #endif
turesnake/tprPixelGames
src/Engine/tprDebug/tprCast.h
/* * ======================= tprCast.h ========================== * -- tpr -- * CREATE -- 2019.06.09 * MODIFY -- * ---------------------------------------------------------- * type cast * --------------------- */ #ifndef TPR_CAST_H #define TPR_CAST_H #include "tprAssert.h" /* =========================================================== * cast_2_size_t * ----------------------------------------------------------- * signed_integer -> size_t * 如果参数为负,直接 tprAssert 退出 */ inline size_t assert_and_return_( const char *file_, int line_ )noexcept{ tprAssert_inn(0, file_, line_); return 0; } #define cast_2_size_t(e) (((e)>=0) ? static_cast<size_t>(e) : assert_and_return_(__FILE__, __LINE__)) // MUST wrap a "(...)" outside !!! #endif
turesnake/tprPixelGames
src/Engine/input/InputOriginData.h
<reponame>turesnake/tprPixelGames<filename>src/Engine/input/InputOriginData.h /* * ======================== InputOriginData.h ========================== * -- tpr -- * 创建 -- 2020.01.25 * 修改 -- * ---------------------------------------------------------- * 仅在 firstPlayInputSet 阶段启用。 * 每一帧,都完整地读取,所有支持地 外设的 数据 */ #ifndef TPR_INPUT_ORIGIN_DATA_H #define TPR_INPUT_ORIGIN_DATA_H //--- glm - 0.9.9.5 --- #include "glm_no_warnings.h" //-------------------- CPP --------------------// #include <string> #include <vector> #include <set> #include <memory> #include <unordered_map> //-------------------- Engine --------------------// #include "tprAssert.h" #include "KeyBoard.h" #include "Joystick.h" #include "Mouse.h" class InputOriginData{ public: InputOriginData()=default; // 读取系统中,所有连接的,支持 SDL_GameControllerDB 的 手柄信息 std::unordered_map<int, std::unique_ptr<Joystick>> joysticks {}; Mouse mouse {}; KeyBoard keyboard {}; }; // GLFW_RELEASE == 0 // GLFW_PRESS == 1 // GLFW_REPEAT == 2 本系列函数无视 GLFW_REPEAT inline bool is_GLFW_PRESS( int glfwRet_ )noexcept{ return (glfwRet_==GLFW_PRESS) ? true : false; } inline bool is_GLFW_PRESS( unsigned char glfwRet_ )noexcept{ return (glfwRet_==GLFW_PRESS) ? true : false; } #endif
turesnake/tprPixelGames
src/Engine/input/Joystick.h
<reponame>turesnake/tprPixelGames<gh_stars>100-1000 /* * ======================== Joystick.h ========================== * -- tpr -- * CREATE -- 2020.01.27 * MODIFY -- * ---------------------------------------------------------- */ #ifndef TPR_JOYSTICK_H #define TPR_JOYSTICK_H //=== *** glad FIRST, glfw SECEND *** === // Don't include glfw3.h ALONE!!! #include<glad/glad.h> #include<GLFW/glfw3.h> //--- glm - 0.9.9.5 --- #include "glm_no_warnings.h" //-------------------- CPP --------------------// #include <string> #include <vector> //-------------------- Engine --------------------// #include "tprAssert.h" // support SDL_GameControllerDB // 本游戏 暂时仅支持 这类 joystick class Joystick{ public: enum class Button : size_t{ A = GLFW_GAMEPAD_BUTTON_A, B = GLFW_GAMEPAD_BUTTON_B, X = GLFW_GAMEPAD_BUTTON_X, Y = GLFW_GAMEPAD_BUTTON_Y, LB = GLFW_GAMEPAD_BUTTON_LEFT_BUMPER, RB = GLFW_GAMEPAD_BUTTON_RIGHT_BUMPER, Back = GLFW_GAMEPAD_BUTTON_BACK, Start = GLFW_GAMEPAD_BUTTON_START, Guide = GLFW_GAMEPAD_BUTTON_GUIDE, LeftThumb = GLFW_GAMEPAD_BUTTON_LEFT_THUMB, RightThumb = GLFW_GAMEPAD_BUTTON_RIGHT_THUMB, Hat_Up = GLFW_GAMEPAD_BUTTON_DPAD_UP, Hat_Right = GLFW_GAMEPAD_BUTTON_DPAD_RIGHT, Hat_Down = GLFW_GAMEPAD_BUTTON_DPAD_DOWN, Hat_Left = GLFW_GAMEPAD_BUTTON_DPAD_LEFT, }; //========== Selfs ==========// explicit Joystick( int connectIdx_ ): connectIdx(connectIdx_) { this->name = glfwGetJoystickName( this->connectIdx ); this->gamePadName = glfwGetGamepadName( this->connectIdx ); } void refresh()noexcept; //------- get -------// inline bool get_isAnyAxisPress()const noexcept{ return this->isAnyAxisPress; } inline bool get_isAnyButtonPress()const noexcept{ return this->isAnyButtonPress; } inline bool get_button( Button b_ )const noexcept{ return (this->state.buttons[ static_cast<size_t>(b_) ] == GLFW_PRESS); } inline glm::dvec2 get_LeftAxes()const noexcept{ return glm::dvec2{ static_cast<double>( state.axes[GLFW_GAMEPAD_AXIS_LEFT_X] ), static_cast<double>( state.axes[GLFW_GAMEPAD_AXIS_LEFT_Y] ) }; } inline glm::dvec2 get_RightAxes()const noexcept{ return glm::dvec2{ static_cast<double>( state.axes[GLFW_GAMEPAD_AXIS_RIGHT_X] ), static_cast<double>( state.axes[GLFW_GAMEPAD_AXIS_RIGHT_Y] ) }; } inline double get_LT()const noexcept{ return static_cast<double>( state.axes[GLFW_GAMEPAD_AXIS_LEFT_TRIGGER] ); } inline double get_RT()const noexcept{ return static_cast<double>( state.axes[GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER] ); } private: //--- idx ---// int connectIdx; //--- strs ---// std::string name {}; // glfw 读取的 name std::string gamePadName {}; // 在 SDL_GameControllerDB 中登记的 name GLFWgamepadstate state {}; // 完整的数据 //===== flags =====// bool isAnyAxisPress {false}; // 是否有任一轴 发生输入 bool isAnyButtonPress {false}; // 是否有某任一按钮 发生输入 }; #endif
turesnake/tprPixelGames
deps/stb_image/stb_image_no_warnings.h
/* * =================== stb_image_no_warnings.h ================= * -- tpr -- * CREATE -- 2019.06.08 * MODIFY -- * ---------------------------------------------------------- */ #ifndef TPR_STB_IMAGE_NO_WARNINGS_H_ #define TPR_STB_IMAGE_NO_WARNINGS_H_ //-- 屏蔽掉 stb_image 中的所有 warnings -- #pragma clang system_header #ifndef STB_IMAGE_IMPLEMENTATION #define STB_IMAGE_IMPLEMENTATION #endif #include "stb_image_inn/stb_image.h" //-- 加载图片数据用 #endif
turesnake/tprPixelGames
src/Engine/gameObj/PubBinary.h
<reponame>turesnake/tprPixelGames /* * ==================== PubBinary.h ===================== * -- tpr -- * CREATE -- 2019.02.03 * MODIFY -- * ---------------------------------------------------------- */ #ifndef TPR_PUB_BINARY_H #define TPR_PUB_BINARY_H //-------------------- CPP --------------------// #include <vector> #include <unordered_map> //-------------------- Engine --------------------// #include "tprAssert.h" #include "PubBinaryValType.h" //-- 维护一个 二进制块,可以动态存储 各种 pubBinary变量(一种一个) class PubBinary{ using idx_t = uint32_t; //- pubBinaryValTyprIdx using byteoff_t = uint32_t; //- byte_off in binary public: PubBinary() = default; //- 通过一个 变量类型表,一次性注册所有变量 inline void init( const std::vector<PubBinaryValType> &types_ ){ idx_t idx {}; //- tmp byteoff_t off {0}; for( const auto &i : types_ ){ idx = static_cast<idx_t>(i); auto [insertIt, insertBool] = valOffs.emplace( idx, off ); tprAssert( insertBool ); off += (byteoff_t)(get_PubBinaryValSizes().at(idx)); } binary.resize( off ); } inline bool check( PubBinaryValType type_ ) const { return (valOffs.find((idx_t)type_)!=valOffs.end()); } //- 仅返回 void*, 需要调用者自行转换为 对应的 指针类型... // 此指针同时提供 读写权限 // 使用前 应主动调用 check() inline void *get_valPtr( PubBinaryValType type_ ) const { const byteoff_t &off = valOffs.at((idx_t)type_); return reinterpret_cast<void*>( const_cast<uint8_t*>(&(binary.at(off))) ); //- first remove const,then reinterpret_cast } private: std::unordered_map<idx_t, byteoff_t> valOffs {}; //- 记载 某个变量 是否被注册,以及它在 binary中的 地址偏移 std::vector<uint8_t> binary {}; //- 所有变量 真实存储区 }; #endif
turesnake/tprPixelGames
src/Engine/map/fieldFractType.h
/* * ====================== fieldFractType.h ======================= * -- tpr -- * CREATE -- 2019.09.30 * MODIFY -- * ---------------------------------------------------------- */ #ifndef TPR_GROUND_GO_ENT_TYPE_H #define TPR_GROUND_GO_ENT_TYPE_H // 分割一个 field 变成跟小的单位 enum class FieldFractType{ MapEnt, HalfField, Field, }; #endif
turesnake/tprPixelGames
src/Script/gameObjs/majorGos/trees/PineTree.h
/* * ========================= PineTree.h ========================== * -- tpr -- * CREATE -- 2019.09.13 * MODIFY -- * ---------------------------------------------------------- */ #ifndef TPR_GO_PINE_TREE_H #define TPR_GO_PINE_TREE_H //-------------------- Engine --------------------// #include "GameObj.h" #include "DyParam.h" namespace gameObjs{//------------- namespace gameObjs ---------------- class PineTree{ 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/multiThread/jobThread.h
/* * ======================= JobThread.h ======================= * -- tpr -- * CREATE -- 2019.04.24 * MODIFY -- * ---------------------------------------------------------- * 游戏存在一个 主线程,和数个 job线程 * 主线程 向 esrc::jobQue 写入 job。 * job线程 从 esrc::jobQue 取出job,并完成它们 * ---------------------------- */ #ifndef TPR_JOB_THREAD_H #define TPR_JOB_THREAD_H void jobThread_main(); #endif
turesnake/tprPixelGames
src/Engine/shaderProgram/ubo_all.h
/* * ======================= ubo_all.h ========================== * -- tpr -- * CREATE -- 2019.09.24 * MODIFY -- * ---------------------------------------------------------- */ #ifndef TPR_UBO_ALL_H #define TPR_UBO_ALL_H //--- glm - 0.9.9.5 --- #include "glm_no_warnings.h" //-------------------- Engine --------------------// #include "FloatVec.h" #include "colorTableId.h" //... namespace ubo{//------------- namespace ubo ---------------- //-------------------------// // UBO_Camera //-------------------------// // struct: // glm::mat4 mat4_view (64) // glm::mat4 mat4_projection (64) // FloatVec2 canvasCFPos (8) // ... inline constexpr size_t UBO_Camera_size { 64 + 64 + 8 }; // called when: // -1- app.init // -2- camera state changed void write_ubo_Camera(); //-------------------------// // UBO_Seeds //-------------------------// // [once] struct UBO_Seeds{ FloatVec2 altiSeed_pposOffSeaLvl {}; FloatVec2 altiSeed_pposOffBig {}; FloatVec2 altiSeed_pposOffMid {}; FloatVec2 altiSeed_pposOffSml {}; //.... }; void write_ubo_Seeds(); //-------------------------// // UBO_Time //-------------------------// // [tmp once] struct UBO_Time{ float currentTime {}; //.... }; // called every render frmae void write_ubo_Time(); //-------------------------// // UBO_Window //-------------------------// // [tmp once] struct UBO_Window{ FloatVec2 gameSZ {}; // equal to ViewingBox::gameSZ //.... }; // only called in: // -1- app.init // -2- windowSZ changed (never yet...) void write_ubo_Window(); //-------------------------// // UBO_WorldCoord //-------------------------// // [once] struct UBO_WorldCoord{ FloatVec2 xVec {}; FloatVec2 yVec {}; float denominator {}; //.... }; // only called in init void write_ubo_WorldCoord(); //-------------------------// // UBO_ColorTable //-------------------------// void write_ubo_OriginColorTable(); void update_and_write_ubo_UnifiedColorTable(); void write_ubo_GroundColorTable(); void write_ubo_colorTableId( colorTableId_t id_ ); }//------------- namespace ubo: end ---------------- #endif
turesnake/tprPixelGames
src/Engine/tools/Behaviour.h
/* * ========================= Behaviour.h ========================== * -- tpr -- * CREATE -- 2018.11.24 * MODIFY -- * ---------------------------------------------------------- */ #ifndef TPR_BEHAVIOUR_H #define TPR_BEHAVIOUR_H //-------------------- CPP --------------------// #include <string> #include <vector> #include <functional> //-------------------- Engine --------------------// #include "functorTypes.h" //-- 设计思路类似 u3d 中的 MonoBehaviour/Behaviour, 但更为简单 -- // 本类只有一个 全局变量 class Behaviour{ public: Behaviour() = default; //------------- sign up -------------// inline void signUp_Awakes( F_void func_ )noexcept{ Awakes.push_back(func_); } inline void signUp_Starts( F_void func_ )noexcept{ Starts.push_back(func_); } inline void signUp_Updates( F_void func_ )noexcept{ Updates.push_back(func_); } //------------- call -------------// inline void call_Awakes()noexcept{ call_funcs( Awakes ); } inline void call_Starts()noexcept{ call_funcs( Starts ); } inline void call_Updates()noexcept{ call_funcs( Updates ); } private: inline void call_funcs( const std::vector<F_void> &funcs_ )noexcept{ if( funcs_.size() == 0 ){ return; } for( const auto &i : funcs_ ){ if( i != nullptr ){ i(); } } } //======== vals ========// std::vector<F_void> Awakes {}; //- 在引擎运作之前 std::vector<F_void> Starts {}; //- 在主循环开启之前 std::vector<F_void> Updates {}; //- 在主循环的每一回合中 // 这个 Updates 是每帧执行一次,还是 每n帧 执行一次 // 目前还没有想好 }; #endif
turesnake/tprPixelGames
deps/spdlog/details/tcp_client.h
<gh_stars>100-1000 // Copyright(c) 2015-present, <NAME> & spdlog contributors. // Distributed under the MIT License (http://opensource.org/licenses/MIT) #pragma once #ifdef _WIN32 #error tcp_client not supported under windows yet #endif // tcp client helper #include <spdlog/common.h> #include <spdlog/details/os.h> #include <sys/socket.h> #include <arpa/inet.h> #include <unistd.h> #include <netdb.h> #include <netinet/tcp.h> #include <string> namespace spdlog { namespace details { class tcp_client { int socket_ = -1; public: bool is_connected() const { return socket_ != -1; } void close() { if (is_connected()) { ::close(socket_); socket_ = -1; } } int fd() const { return socket_; } ~tcp_client() { close(); } // try to connect or throw on failure void connect(const std::string &host, int port) { close(); struct addrinfo hints {}; memset(&hints, 0, sizeof(struct addrinfo)); hints.ai_family = AF_INET; // IPv4 hints.ai_socktype = SOCK_STREAM; // TCP hints.ai_flags = AI_NUMERICSERV; // port passed as as numeric value hints.ai_protocol = 0; auto port_str = std::to_string(port); struct addrinfo *addrinfo_result; auto rv = ::getaddrinfo(host.c_str(), port_str.c_str(), &hints, &addrinfo_result); if (rv != 0) { auto msg = fmt::format("::getaddrinfo failed: {}", gai_strerror(rv)); SPDLOG_THROW(spdlog::spdlog_ex(msg)); } // Try each address until we successfully connect(2). int last_errno = 0; for (auto *rp = addrinfo_result; rp != nullptr; rp = rp->ai_next) { #ifdef SPDLOG_PREVENT_CHILD_FD int const flags = SOCK_CLOEXEC; #else int const flags = 0; #endif socket_ = ::socket(rp->ai_family, rp->ai_socktype | flags, rp->ai_protocol); if (socket_ == -1) { last_errno = errno; continue; } rv = ::connect(socket_, rp->ai_addr, rp->ai_addrlen); if (rv == 0) { break; } else { last_errno = errno; ::close(socket_); socket_ = -1; } } ::freeaddrinfo(addrinfo_result); if (socket_ == -1) { SPDLOG_THROW(spdlog::spdlog_ex("::connect failed", last_errno)); } // set TCP_NODELAY int enable_flag = 1; ::setsockopt(socket_, IPPROTO_TCP, TCP_NODELAY, (char *)&enable_flag, sizeof(enable_flag)); // prevent sigpipe on systems where MSG_NOSIGNAL is not available #if defined(SO_NOSIGPIPE) && !defined(MSG_NOSIGNAL) ::setsockopt(socket_, SOL_SOCKET, SO_NOSIGPIPE, (char *)&enable_flag, sizeof(enable_flag)); #endif #if !defined(SO_NOSIGPIPE) && !defined(MSG_NOSIGNAL) #error "tcp_sink would raise SIGPIPE since niether SO_NOSIGPIPE nor MSG_NOSIGNAL are available" #endif } // Send exactly n_bytes of the given data. // On error close the connection and throw. void send(const char *data, size_t n_bytes) { size_t bytes_sent = 0; while (bytes_sent < n_bytes) { #if defined(MSG_NOSIGNAL) const int send_flags = MSG_NOSIGNAL; #else const int send_flags = 0; #endif auto write_result = ::send(socket_, data + bytes_sent, n_bytes - bytes_sent, send_flags); if (write_result < 0) { close(); SPDLOG_THROW(spdlog::spdlog_ex("write(2) failed", errno)); } if (write_result == 0) // (probably should not happen but in any case..) { break; } bytes_sent += static_cast<size_t>(write_result); } } }; } // namespace details } // namespace spdlog
turesnake/tprPixelGames
src/Engine/ecoSys/EcoSysPlan.h
<reponame>turesnake/tprPixelGames<filename>src/Engine/ecoSys/EcoSysPlan.h /* * ========================= EcoSysPlan.h ======================= * -- tpr -- * CREATE -- 2019.02.22 * MODIFY -- * ---------------------------------------------------------- * ecosystem plan * ---------------------------- */ #ifndef TPR_ECOSYS_PLAN_H #define TPR_ECOSYS_PLAN_H #include "pch.h" //-------------------- Engine --------------------// #include "RGBA.h" #include "GameObjType.h" #include "ID_Manager.h" #include "EcoSysPlanType.h" #include "GoSpecData.h" #include "colorTableId.h" #include "blueprint.h" #include "Density.h" #include "GoAssemblePlan.h" #include "DensityPool.h" class Density; //-- 一种 生态群落 -- // 简易版,容纳最基础的数据 // 在未来一点点丰富细节 class EcoSysPlan{ public: EcoSysPlan() = default; inline void set_id( ecoSysPlanId_t id_ )noexcept{ this->id = id_; } inline void set_type( EcoSysPlanType type_ )noexcept{ this->type = type_; } inline void set_colorTableId( colorTableId_t id_ )noexcept{ this->colorTableId = id_; } inline void insert_2_villageIdRandPool( blueprint::villageBlueprintId_t id_, size_t num_ )noexcept{ this->villageIdRandPool.insert( this->villageIdRandPool.end(), num_, id_ ); } inline void insert_2_natureFlooryardIdRandPool( blueprint::yardBlueprintId_t id_, size_t num_ )noexcept{ this->natureFlooryardIdRandPool.insert( this->natureFlooryardIdRandPool.end(), num_, id_ ); } inline void insert_2_natureFloorDensitys( Density density_ )noexcept{ auto [insertIt, insertBool] = this->natureFloorDensitys.insert( density_ ); tprAssert( insertBool ); } void init_densityDatas( double densitySeaLvlOff_, const std::vector<double> &datas_ ); inline DensityPool &create_new_densityPool( Density density_ )noexcept{ auto [insertIt, insertBool] = this->densityPools.emplace( density_, std::make_unique<DensityPool>() ); tprAssert( insertBool ); return *(insertIt->second); } //-- 确保关键数据 都被初始化 -- void init_check()noexcept; inline ecoSysPlanId_t get_id()const noexcept{ return this->id; } inline EcoSysPlanType get_type()const noexcept{ return this->type; } inline colorTableId_t get_colorTableId()const noexcept{ return this->colorTableId; } inline double get_densitySeaLvlOff() const noexcept{ return this->densitySeaLvlOff; } //-- 主要用来 复制给 ecoObj 实例 -- inline const std::vector<double> *get_densityDivideValsPtr() const noexcept{ return &(this->densityDivideVals); } //-- 临时版本 ......... inline const std::map<Density, std::unique_ptr<DensityPool>> & get_densityPools()const noexcept{ return this->densityPools; } inline blueprint::villageBlueprintId_t apply_rand_villageBlueprintId( size_t uWeight_ )const noexcept{ return this->villageIdRandPool.at( (uWeight_ + 7337507) % this->villageIdRandPool.size() ); } inline blueprint::yardBlueprintId_t apply_rand_natureFlooryardId( size_t uWeight_ )const noexcept{ return this->natureFlooryardIdRandPool.at( (uWeight_ + 71010107) % this->natureFlooryardIdRandPool.size() ); } inline const std::set<Density> *get_natureFloorDensitysPtr()const noexcept{ return &(this->natureFloorDensitys); } //======== static ========// static ID_Manager id_manager; private: //======== vals ========// ecoSysPlanId_t id {}; EcoSysPlanType type {EcoSysPlanType::Forest}; colorTableId_t colorTableId {}; double densitySeaLvlOff {0.0}; //-- field.nodeAlit.val > 30; //-- field.density.lvl [-3, 3] 共 7个池子 //-- 用 density.get_idx() 来遍历 std::vector<double> densityDivideVals {}; //- 6 ents, each_ent: [-100.0, 100.0] std::map<Density, std::unique_ptr<DensityPool>> densityPools {}; //----- blueprints -----// std::vector<blueprint::villageBlueprintId_t> villageIdRandPool {}; // 随机分配池 // village 也应该具备 尺寸区别 // 并且用不同尺寸的容器来存储 // 未实现 ... //-- nature_floorYard --// std::vector<blueprint::yardBlueprintId_t> natureFlooryardIdRandPool {}; // nature floor yard std::set<Density> natureFloorDensitys {}; // 哪些 density 需要分配 natureFloorYard //===== flags =====// bool is_densityDivideVals_init {false}; }; #endif
turesnake/tprPixelGames
src/Engine/tools/ID_Manager.h
<filename>src/Engine/tools/ID_Manager.h /* * ========================= ID_Manager.h ========================== * -- tpr -- * CREATE -- 2018.12.10 * MODIFY -- * ---------------------------------------------------------- */ #ifndef TPR_ID_MANAGER_H #define TPR_ID_MANAGER_H //------------------- CPP --------------------// #include <cstdint> // uint8_t //------------------- Engine --------------------// #include "tprAssert.h" //-- id 默认从 1 开始增长。0号id 被保留,表示空id -- //extern const int NULLID; #define NULLID 0 //-- int 类型有麻烦... //-- id类型(取值范围)-- enum class ID_TYPE : uint8_t { U8 = 1, //- [1,255] U16 = 2, //- [1,65535] U32 = 3, //- [1,4294967295] U64 = 4 //- [1, infinity...] }; //----- id 管理器 ----- // 通常作为 其他类的 静态成员 存在。 // 0 号 id 一定不会被分配到 class ID_Manager{ public: ID_Manager( ID_TYPE id_type_=ID_TYPE::U64, uint64_t max_id_=0 ): id_scope(id_type_), max_id(max_id_) { switch( this->id_scope ){ case ID_TYPE::U8: this->id_limit = static_cast<uint8_t>(-1); break; case ID_TYPE::U16: this->id_limit = static_cast<uint16_t>(-1); break; case ID_TYPE::U32: this->id_limit = static_cast<uint32_t>(-1); break; case ID_TYPE::U64: this->id_limit = static_cast<uint64_t>(-1); break; //- 用不到 default: tprAssert(0); //- 不会运行到此行 } } inline uint8_t apply_a_u8_id() noexcept { tprAssert( this->id_scope == ID_TYPE::U8 ); this->max_id++; tprAssert( this->max_id <= this->id_limit );//-- 2^8 -- return static_cast<uint8_t>(this->max_id); } inline uint16_t apply_a_u16_id() noexcept { tprAssert( this->id_scope == ID_TYPE::U16 ); this->max_id++; tprAssert( this->max_id <= this->id_limit );//-- 2^16 -- return static_cast<uint16_t>(this->max_id); } inline uint32_t apply_a_u32_id() noexcept { tprAssert( this->id_scope == ID_TYPE::U32 ); this->max_id++; tprAssert( this->max_id <= this->id_limit );//-- 2^32 -- return static_cast<uint32_t>(this->max_id); } inline uint64_t apply_a_u64_id() noexcept { tprAssert( this->id_scope == ID_TYPE::U64 ); this->max_id++; //-- 2^64 个id,永远也用不完。 return this->max_id; } inline void set_max_id( uint64_t max_id_ ) noexcept { this->max_id = max_id_; } inline uint64_t get_max_id() const noexcept { return this->max_id; } private: ID_TYPE id_scope; //- id类型 uint64_t max_id; //- 当前 使用的 数值最大的 id号 uint64_t id_limit; //- id号 上限 }; #endif
turesnake/tprPixelGames
src/Engine/gameObj/GameObjType.h
<filename>src/Engine/gameObj/GameObjType.h /* * ===================== GameObjType.h ========================== * -- tpr -- * CREATE -- 2018.12.11 * MODIFY -- * ---------------------------------------------------------- * GameObj 各种数据 结构 * ---------------------------- */ #ifndef TPR_GAME_OBJ_TYPE_H #define TPR_GAME_OBJ_TYPE_H //-------------------- CPP --------------------// #include <string> #include <functional> class GameObj; //class UIObj; class DyParam; //-- map自动生成器 使用的 uiInit函数 --- using F_GO_INIT = std::function<void(GameObj&, const DyParam &dyParams_)>; using F_GO = std::function<void( GameObj& )>; using F_AFFECT = std::function<void( GameObj&, GameObj& )>; // params: dogoRef_, begoRef_ using goid_t = uint64_t; //- gameObj id type using goSpeciesId_t = uint64_t; //- gameObj species id type. = goSpeciesName.hash() // 并不直接使用 size_t, 确保 数据库中数据 一定对其 //-- go move state/运动状态 -- enum class GameObjMoveState{ AbsFixed = 1, //- 固定于地面,绝对静止。 需要对齐于 像素 BeMovable = 2, //- 静止,但可被移动(通过外部 forse 施加的影响) // 从未被使用,将被废弃 ... Movable = 3 //- 可移动。本go 可启动移动操作。 }; GameObjMoveState str_2_gameObjMoveState( const std::string &name_ )noexcept; //-- go state / go 常规状态 -- enum class GameObjState{ Sleep = 1, //- 休眠状态,不主动行动,(但可被动回应) Waked = 2 //- 活跃状态,主动发起行动。 }; GameObjState str_2_gameObjState( const std::string &name_ )noexcept; //- 三大 go 类群 -- // 这套系统使用使用,暂未确定 enum class GameObjFamily{ Major = 1, // 主go: 活体,树,建筑... // 只有 MajorGo / BioSoup,可以参与 游戏世界的 碰撞检测 // 会被登记到对应 chunk 中 (从而可以跟随chunk 被释放) // 会被登记到对应 mapent 中,从而可以进行 移动/技能 碰撞检测 BioSoup, // 异世界生物汤。 // 只有 MajorGo / BioSoup,可以参与 游戏世界的 碰撞检测 // 会被登记到对应 chunk 中 (从而可以跟随chunk 被释放) // 会被登记到对应 mapent 中,从而可以进行 移动/技能 碰撞检测 // 特性上非常类似 普通的 mp-go Floor, // 地面材质go (无法移动) // 会被登记到对应 chunk 中 (从而可以跟随chunk 被释放) // 不被登记到对应 mapent 中 GroundGo, // 折中产物,为地面铺设一层 eco 主体色 (无法移动) // 会被登记到对应 chunk 中 (从而可以跟随chunk 被释放) // 不被登记到对应 mapent 中 WorldUI, // 被放置在 游戏世界内 的 uiGo, // 比如跟随 活体移动的 血条/ 特效 等 // 暂时只有 playerGoCircle. // 会被登记到对应 chunk 中 (从而可以跟随chunk 被释放) // 不被登记到对应 mapent 中 // --- // 布恩 WorldUI-go 是要移动的,不要忘记更新 它们的 chunk登记信息!!! UI, // 被合并进 GO 的 UIGO 类, 无需执行 worldCoord 转换 // 它们不应该出现在 游戏世界空间中,而独立存在于 ui空间 中 // 如果某个 ui-go,需要被放置在 游戏世界空间 内,应被设置为 WorldUI // --- // 由于 UI-go 并不存在于 游戏世界空间,所以和 chunk/mapent 完全无关 }; GameObjFamily str_2_gameObjFamily( const std::string &name_ )noexcept; #endif
turesnake/tprPixelGames
src/Engine/player/Player.h
/* * ====================== Player.h ======================= * -- tpr -- * CREATE -- 2018.12.09 * MODIFY -- * ---------------------------------------------------------- * 存储所有 玩家 信息。 * ---------- * ---------------------------- */ #ifndef TPR_PLAYER_H #define TPR_PLAYER_H //-------------------- Engine --------------------// #include "IntVec.h" #include "GameObjType.h" #include "ID_Manager.h" #include "SpeedLevel.h" #include "InputINS.h" // need: class GameObj; //-- 玩家数据 [内存态] -- //- 独一无二的存在,在 游戏中只有一份 class Player{ public: Player() = default; //-- 必须等 chunks 彻底加载到 mem态(相伴的go数据也实例化)之后 -- // 才能调用本函数 void bind_go( goid_t goid_ ); void handle_inputINS( const InputINS &inputINS_ ); GameObj &get_goRef() const; void set_moveSpeedLvl( SpeedLevel lvl_ )noexcept; //======== vals ========// goid_t goid {NULLID}; // 不再长期持有 goPtr,而是持有 goid,随用随取。 // 忽略这点性能损失 goid_t playerGoCircle_goid {NULLID}; // 这个 go实例 伴随 player实例 整个生命周期 private: }; #endif
turesnake/tprPixelGames
src/Engine/gameObj/goDataForCreate/goLabelId.h
<filename>src/Engine/gameObj/goDataForCreate/goLabelId.h /* * ======================= goLabelId.h ===================== * -- tpr -- * CREATE -- 2020.02.25 * MODIFY -- * ---------------------------------------------------------- */ #ifndef TPR_GO_LABEL_ID_H #define TPR_GO_LABEL_ID_H #include <cstddef> using goLabelId_t = size_t; // std::hash #endif
turesnake/tprPixelGames
src/Engine/resource/esrc_state.h
/* * ========================= esrc_state.h ========================== * -- tpr -- * CREATE -- 2019.09.29 * MODIFY -- * ---------------------------------------------------------- */ #ifndef TPR_ESRC_STATE_H #define TPR_ESRC_STATE_H //-------------------- CPP --------------------// #include <string> namespace esrc {//------------------ namespace: esrc -------------------------// void insertState( const std::string &str_ ); bool is_setState( const std::string &str_ ); }//---------------------- namespace: esrc -------------------------// #endif
turesnake/tprPixelGames
src/Engine/resource/esrc_job_chunk.h
/* * ====================== esrc_Job_Chunk.h ========================== * -- tpr -- * CREATE -- 2019.04.19 * MODIFY -- * ---------------------------------------------------------- */ #ifndef TPR_ESRC_JOB_CHUNK_H #define TPR_ESRC_JOB_CHUNK_H #include <optional> //-------------------- Engine --------------------// #include "Job_Chunk.h" #include "chunkKey.h" namespace esrc {//------------------ namespace: esrc -------------------------// void init_job_chunks(); Job_Chunk &atom_insert_new_job_chunk( chunkKey_t chunkKey_ ); void atom_erase_from_job_chunks( chunkKey_t chunkKey_ ); std::optional<Job_Chunk*> atom_getnc_job_chunk_ptr( chunkKey_t chunkKey_ ); void atom_push_back_2_job_chunkFlags( chunkKey_t chunkKey_ ); std::optional<chunkKey_t> atom_pop_from_job_chunkFlags(); }//---------------------- namespace: esrc -------------------------// #endif
turesnake/tprPixelGames
src/Engine/move/Move.h
/* * ========================= Move.h ========================== * -- tpr -- * CREATE -- 2019.01.13 * MODIFY -- * ---------------------------------------------------------- */ #ifndef TPR_MOVE_H #define TPR_MOVE_H //-------------------- CPP --------------------// #include <functional> #include <memory> #include <string> //-------------------- Engine --------------------// #include "tprAssert.h" #include "functorTypes.h" #include "SpeedLevel.h" #include "MapCoord.h" #include "DirAxes.h" #include "History.h" //-- need -- class GameObj; class GameObjPos; class Collision; enum class MoveType : int { Crawl, // often used for regular Go, with uniform speed [have speed upper limit] Drag, // often used for regular Go, with uniform speed [have speed upper limit] Adsorb, // often used for UIGo, with smooth speed change [no speed upper_limit] }; MoveType str_2_moveType( const std::string name_ )noexcept; class Move{ public: explicit Move( GameObj &goRef_ ): goRef(goRef_) {} inline void RenderUpdate()noexcept{ this->renderUpdateFunc(); } //------- flags -------// inline bool is_crawl() const noexcept{ return (this->moveType==MoveType::Crawl); } inline bool is_drag() const noexcept{ return (this->moveType==MoveType::Drag); } inline bool is_adsorb() const noexcept{ return (this->moveType==MoveType::Adsorb); } //------- set -------// inline void set_MoveType( MoveType type_ )noexcept{ this->moveType = type_; switch ( type_ ){ case MoveType::Crawl: this->renderUpdateFunc = std::bind( &Move::renderUpdate_crawl, this ); this->isMovingFunc = [this_l=this](){ if( this_l->moveSpeedLvl.get_newVal() == SpeedLevel::LV_0 ){ return false; } return !this_l->crawlDirAxes.get_newVal().is_zero(); }; return; case MoveType::Drag: this->renderUpdateFunc = std::bind( &Move::renderUpdate_drag, this ); this->isMovingFunc = [this_l=this](){ if( this_l->moveSpeedLvl.get_newVal() == SpeedLevel::LV_0 ){ return false; } return this_l->isMoving; }; return; case MoveType::Adsorb: this->renderUpdateFunc = std::bind( &Move::renderUpdate_adsorb, this ); this->isMovingFunc = [this_l=this](){ return this_l->isMoving; }; return; default: tprAssert(0); return; } } void set_newCrawlDirAxes( const DirAxes &newDirAxes_ ); inline void set_drag_targetDPos( const glm::dvec2 &DPos_ )noexcept{ tprAssert( this->is_drag() ); if( DPos_ == this->targetDPos ){ return; } this->targetDPos = DPos_; this->isMoving = true; } inline void set_adsorb_targetDPos( const glm::dvec2 &DPos_ )noexcept{ tprAssert( this->is_adsorb() ); if( DPos_ == this->targetDPos ){ return; } this->targetDPos = DPos_; this->isMoving = true; } //------- get -------// inline bool get_isMoving()const noexcept{ return this->isMovingFunc(); } //---- history vals ----// // stone val-state at last render-frame History<DirAxes> crawlDirAxes { DirAxes{} }; // only used at Crawl-mode History<SpeedLevel> moveSpeedLvl { SpeedLevel::LV_0 }; private: void renderUpdate_crawl(); void renderUpdate_drag(); void renderUpdate_adsorb(); //===== vals =====// GameObj &goRef; MoveType moveType { MoveType::Crawl }; glm::dvec2 targetDPos {-987654321.98765,-987654321.98765}; //- 设置一个不可能指向的 初始值。防止 第一次使用 set_drag_targetDPos() 时 // 就引发 targetDPos 初始值 等于 目标值。从而 drag 失效 // 一种很简陋,但有效的办法 //------- functor -------// F_void renderUpdateFunc {nullptr}; //- 只在初始化阶段绑定,也许未来是可以切换的,但目前未实现 F_bool isMovingFunc {nullptr}; //===== flags =====// bool isMoving {false}; // ==false 时,渲染层才会执行 mesh 像素对齐操作 // 暂时,仅用于 Drag, Adsord 两模式 }; #endif
turesnake/tprPixelGames
src/Engine/AI/AI_Crab.h
/* * ========================= AI_Crab.h ========================== * -- tpr -- * CREATE -- 2019.05.09 * MODIFY -- * ---------------------------------------------------------- * 螃蟹式 AI * ----------------------- */ #ifndef TPR_AI_CRAB_H #define TPR_AI_CRAB_H #include "pch.h" //-------------------- Engine --------------------// #include "GameObj.h" #include "functorTypes.h" class AI_Crab{ public: AI_Crab() = default; inline void init( )noexcept{ //this->goid = goid_; } //void logicUpdate(); inline void bind_get_tmpVal_functor( const F_R_int &functor_ )noexcept{ this->get_tmpVal_functor = functor_; } private: //GameObj *goPtr {nullptr}; //std::weak_ptr<GameObj> goWPtr {}; //goid_t goid {}; //-- tmp F_1 get_tmpVal_functor {nullptr}; //int tmpCount {0}; 未被使用... }; #endif
turesnake/tprPixelGames
src/Engine/gameObj/GoFunctorLabel.h
/* * ====================== GoFunctorLabel.h ========================== * -- tpr -- * CREATE -- 2020.02.12 * MODIFY -- * ---------------------------------------------------------- */ #ifndef TPR_GO_FUNTOR_LABEL_H #define TPR_GO_FUNTOR_LABEL_H //------------------- CPP --------------------// #include <string> #include <cstdint> // uint8_t // GoFunctorSet :key enum class GoFunctorLabel : uint32_t { Nil=0, // 空值 Tmp, //... }; GoFunctorLabel str_2_goFunctorLabel( const std::string &str_ )noexcept; std::string goFunctorLabel_2_str( GoFunctorLabel l_ )noexcept; #endif
turesnake/tprPixelGames
src/Engine/UI/Canvas.h
/* * ========================= Canvas.h ========================== * -- tpr -- * 创建 -- 2019.03.31 * 修改 -- * ---------------------------------------------------------- * canvas 是一个 大型图元,其尺寸和位置 始终与 window 对齐。 * 且不受 camera 影响。 * 通过控制其唯一的 texture,来实现复杂的 动画效果 * ---------------------------- */ #ifndef TPR_CANVAS_H #define TPR_CANVAS_H /* -- 确保 glad GLFW 两个库 的引用顺序 --- * -- glad.h 包含了正确的OpenGL头文件(如GL/gl.h), * -- 所以需要在其它依赖于OpenGL的头文件之前 包含 glad.h */ #include<glad/glad.h> //-------------------- CPP --------------------// #include <vector> #include <string> #include <unordered_map> //-------------------- Engine --------------------// #include "tprAssert.h" #include "IntVec.h" #include "ShaderProgram.h" #include "Mesh.h" class Canvas{ public: Canvas() = default; void init( IntVec2 *texSizePtr_, ShaderProgram *shaderPtr_ ); void draw(); inline void use_shaderProgram()noexcept{ this->is_binded = true; this->shaderPtr->use_program(); } inline void set_translate( float x_, float y_, float z_ )noexcept{ tprAssert( this->is_binded ); this->mesh.set_translate( glm::vec3{ x_, y_, z_ } ); } inline GLint get_uniform_location( const std::string &name_ )noexcept{ tprAssert( this->is_binded ); return this->shaderPtr->get_uniform_location( name_ ); } private: //===== vals =====// IntVec2 *texSizePtr {}; //- = ViewingBox::screenSZ, Mesh mesh {}; ShaderProgram *shaderPtr {nullptr}; //===== flags =====// bool is_binded {false}; //- 统一 绑定/释放, 看起来有点笨拙 }; #endif
turesnake/tprPixelGames
src/Engine/dataBase/dataBase_inn.h
/* * ========================= dataBase_inn.h ========================== * -- tpr -- * CREATE -- 2019.04.29 * MODIFY -- * ---------------------------------------------------------- * only in dataBase inner */ #ifndef TPR_DATA_BASE_INN_H #define TPR_DATA_BASE_INN_H #include "pch.h" //-------------------- CPP --------------------// #include <mutex> //-------------------- Engine --------------------// #include "wrapSqlite3.h" #include "global.h" #include "GameArchive.h" namespace db{//---------------- namespace: db ----------------------// //-- 全游戏唯一的 db connect 实例 -- inline sqlite3 *dbConnect {nullptr}; inline char *zErrMsg {nullptr}; inline int rc {}; inline std::mutex dbMutex; //===== funcs =====// int callback_1(void *data_, int argc_, char **argv_, char **azColNames_); //-- prepare_v2 -- //-- 注意,参数 ppStmt_ 必须为 pp, inline void sqlite3_prepare_v2_inn_( const std::string &sql_str_, sqlite3_stmt **ppStmt_ ){ w_sqlite3_prepare_v2( dbConnect, sql_str_.c_str(), static_cast<int>(sql_str_.size()+1), ppStmt_, nullptr ); } //---- bind vals ---- // 注意:下面这组操作,必须在一个 atom 函数内被调用 -- inline sqlite3_stmt *stmt_for_bindFuncs {nullptr}; inline void reset_stmt_for_bindFuncs_inn_( sqlite3_stmt *newStmt_ ){ stmt_for_bindFuncs = newStmt_; } inline void sqlite3_bind_int_inn_( const std::string &paramStr_, const int &val_ ){ w_sqlite3_bind_int( dbConnect, stmt_for_bindFuncs, w_sqlite3_bind_parameter_index( stmt_for_bindFuncs, paramStr_.c_str() ), val_ ); } inline void sqlite3_bind_int64_inn_( const std::string &paramStr_, const int64_t &val_ ){ w_sqlite3_bind_int64( dbConnect, stmt_for_bindFuncs, w_sqlite3_bind_parameter_index( stmt_for_bindFuncs, paramStr_.c_str() ), val_ ); } inline void sqlite3_bind_double_inn_( const std::string &paramStr_, const double &val_ ){ w_sqlite3_bind_double( dbConnect, stmt_for_bindFuncs, w_sqlite3_bind_parameter_index( stmt_for_bindFuncs, paramStr_.c_str() ), val_ ); } //=============================// // table_gameArchive //=============================// // 主table,存储一切 全局性的数据 inline const std::string sql_create_table_gameArchive { "CREATE TABLE IF NOT EXISTS table_gameArchive(" \ "id INT PRIMARY KEY NOT NULL," \ "baseSeed INT NOT NULL, " \ /* player */ "playerGoId INTEGER NOT NULL, " \ "playerGoDPosX DOUBLE NOT NULL, " \ "playerGoDPosY DOUBLE NOT NULL, " \ /* GameObj */ "maxGoId INTEGER NOT NULL, " \ /* time */ "gameTime DOUBLE NOT NULL " \ ");" \ "PRAGMA journal_mode=WAL;" "SELECT * FROM table_gameArchive" }; //-- 游戏启动初期,将 table_gameArchive 中数据全部读取。 // 由玩家选择,进入哪个存档 inline const std::string sql_select_all_from_table_gameArchive { "SELECT "\ "id, "\ "baseSeed, "\ "playerGoId, "\ "playerGoDPosX, "\ "playerGoDPosY, "\ "maxGoId, "\ "gameTime "\ "FROM table_gameArchive;" }; inline sqlite3_stmt *stmt_select_all_from_table_gameArchive {nullptr}; inline const std::string sql_insert_or_replace_to_table_gameArchive { "INSERT OR REPLACE INTO table_gameArchive (id, baseSeed, playerGoId, playerGoDPosX, playerGoDPosY, maxGoId, gameTime ) " \ "VALUES ( :id, :baseSeed, :playerGoId, :playerGoDPosX, :playerGoDPosY, :maxGoId, :gameTime );" }; inline sqlite3_stmt *stmt_insert_or_replace_to_table_gameArchive {nullptr}; //=============================// // table_chunks //=============================// inline const std::string sql_create_table_chunks { "CREATE TABLE IF NOT EXISTS table_chunks(" \ "chunkKey INTEGER PRIMARY KEY NOT NULL," \ "padding INT NOT NULL " \ ");" }; //=============================// // table_goes //=============================// inline const std::string sql_create_table_goes { "CREATE TABLE IF NOT EXISTS table_goes(" \ "goid INTEGER PRIMARY KEY NOT NULL," \ "goSpeciesId INTEGER NOT NULL, " \ "goLabelId INTEGER NOT NULL, " \ "dposX DOUBLE NOT NULL, " \ "dposY DOUBLE NOT NULL, " \ "goUWeight INTEGER NOT NULL, " \ "dir INTEGER NOT NULL, " \ "brokenLvl INTEGER NOT NULL " \ ");" }; inline const std::string sql_select_one_from_table_goes { "SELECT "\ "goSpeciesId, "\ "goLabelId, "\ "dposX, "\ "dposY, "\ "goUWeight, "\ "dir, "\ "brokenLvl "\ "FROM table_goes WHERE goid = ?;" }; inline sqlite3_stmt *stmt_select_one_from_table_goes {nullptr}; inline const std::string sql_insert_or_replace_to_table_goes { "INSERT OR REPLACE INTO table_goes ( goid, goSpeciesId, goLabelId, dposX, dposY, goUWeight, dir, brokenLvl ) " \ "VALUES ( :goid, :goSpeciesId, :goLabelId, :dposX, :dposY, :goUWeight, :dir, :brokenLvl );" }; inline sqlite3_stmt *stmt_insert_or_replace_to_table_goes {nullptr}; }//----------------------- namespace: db end ----------------------// #endif
turesnake/tprPixelGames
src/Engine/random/simplexNoise.h
/* * ========================= simplexNoise.h ========================== * -- tpr -- * 创建 -- 2019.04.02 * 修改 -- * ---------------------------------------------------------- * glsl版 simplex-noise, 移植到 cpu上 * ---------------------------- */ #ifndef TPR_SIMPLEX_NOISE_H #define TPR_SIMPLEX_NOISE_H //--- glm - 0.9.9.5 --- #include "glm_no_warnings.h" double simplex_noise2( const glm::dvec2 &v_ ); // return [-1.0, 1.0] double simplex_noise2( double x_, double y_ ); // return [-1.0, 1.0] #endif
turesnake/tprPixelGames
src/Engine/gameObj/createGo/create_goes.h
/* * ========================= create_goes.h ========================== * -- tpr -- * CREATE -- 2019.04.10 * MODIFY -- * ---------------------------------------------------------- */ #ifndef TPR_CREATE_GOES_H #define TPR_CREATE_GOES_H //--- glm - 0.9.9.5 --- #include "glm_no_warnings.h" //-------------------- Engine --------------------// #include "IntVec.h" #include "dyParams.h" #include "UIAnchor.h" #include "Chunk.h" //--- need ---// class Job_Chunk; class GameObj; class DiskGameObj; void create_gos_in_field( fieldKey_t fieldKey_, const Chunk &chunkRef_, const Job_Chunk &job_chunkRef_ ); namespace gameObjs{//------------- namespace gameObjs ---------------- goid_t create_a_Go( const GoDataForCreate *goDPtr_ ); void rebind_a_diskGo( const DiskGameObj &diskGo_ ); void signUp_newGO_to_chunk_and_mapEnt( GameObj &goRef_ ); }//------------- namespace gameObjs: end ---------------- namespace uiGos{//------------- namespace uiGos ---------------- goid_t create_a_UIGo( goSpeciesId_t goSpeciesId_, const glm::dvec2 &basePointProportion_, const glm::dvec2 &offDPos_, const DyParam &dyParams_, size_t goUWeight_ ); goid_t create_a_UIGo( goSpeciesId_t goSpeciesId_, const UIAnchor &uiAnchor_, const DyParam &dyParams_, size_t goUWeight_ ); }//------------- namespace uiGos: end ---------------- #endif
turesnake/tprPixelGames
src/Engine/gameObj/GameObj.h
<reponame>turesnake/tprPixelGames<gh_stars>100-1000 /* * ========================= GameObj.h ========================== * -- tpr -- * CREATE -- 2018.11.24 * MODIFY -- * ---------------------------------------------------------- * Fst-class Citizens in game * ---------------------------- */ #ifndef TPR_GAME_OBJ_H #define TPR_GAME_OBJ_H #include "pch.h" //-------------------- CPP --------------------// #include <variant> //-------------------- Engine --------------------// #include "functorTypes.h" #include "GameObjType.h" #include "GameObjMeshSet.h" #include "goLabelId.h" #include "ID_Manager.h" #include "Move.h" #include "MapCoord.h" #include "GameObjPos.h" #include "UIAnchor.h" #include "Collision.h" #include "ColliDataFromJson.h" #include "ActionSwitch.h" //- 将被取代... #include "PubBinary2.h" #include "ActionFSM.h" #include "chunkKey.h" #include "animSubspeciesId.h" #include "DyBinary.h" #include "BrokenLvl.h" #include "History.h" #include "GoFunctorSet.h" #include "ShaderType.h" #include "SignInMapEnts_Square.h" //--- 一个仍在建设中的 丑陋的 大杂烩 ----// // 具象go类 并不用继承 基础go类,而是 “装配” 一个go实例, // 通过 function / bind 动态绑定各种回调函数 // 在 主引擎中,go类 是官方认可的通用类型。也只能通过这个 类来 访问 一切 go实例 //------- // 并不存在孤立的 go实例,每个go实例,都被一个 具象go实例 所"表达“ // goid 是全局唯一的。 其外层的 具象go实例 也使用这个 id号 class GameObj : public std::enable_shared_from_this<GameObj>{ public: //-- factory -- static std::shared_ptr<GameObj> factory_for_regularGo( goid_t goid_, const glm::dvec2 &dpos_, size_t goUWeight_ )noexcept{ std::shared_ptr<GameObj> goSPtr( new GameObj(goid_, goUWeight_) );//- can not use make_shared goSPtr->init_for_regularGo( dpos_ ); return goSPtr; } static std::shared_ptr<GameObj> factory_for_uiGo( goid_t goid_, const glm::dvec2 &basePointProportion_, const glm::dvec2 &offDPos_, size_t goUWeight_ )noexcept{ std::shared_ptr<GameObj> goSPtr( new GameObj(goid_, goUWeight_) );//- can not use make_shared goSPtr->init_for_uiGo( basePointProportion_, offDPos_ ); return goSPtr; } size_t reCollect_chunkKeys(); void rebind_rootAnimActionPosPtr(); //----- 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>(); } template< typename T > inline const T *get_pvtBinaryPtr()const noexcept{ return this->pvtBinary.get<T>(); } void init_check(); //- call in end of go init //--------- rootAnimActionPos ----------// inline Circular calc_circular( CollideFamily family_ )const noexcept{ return this->colliDataFromJsonPtr->calc_circular( this->get_dpos(), family_ ); } inline Square calc_square()const noexcept{ return this->colliDataFromJsonPtr->calc_square( this->get_dpos() ); } inline GoAltiRange get_currentGoAltiRange()noexcept{ return (this->get_pos_lAltiRange() + this->get_pos_alti()); } inline bool find_in_chunkKeys( chunkKey_t chunkKey_ ) const noexcept{ return (this->chunkKeys.find(chunkKey_) != this->chunkKeys.end()); } inline void insert_2_childGoIds( goid_t id_ )noexcept{ auto [insertIt, insertBool] = this->childGoIds.insert(id_); tprAssert( insertBool ); } //-- 确保 所有 History 变量,若存在更新,都已被同步 // 每一渲染帧 末尾调用 inline void make_sure_all_historyVals_is_synced()const noexcept{ tprAssert( !this->actionDirection.get_isDirty() ); tprAssert( !this->brokenLvl.get_isDirty() ); tprAssert( !this->move.moveSpeedLvl.get_isDirty() ); tprAssert( !this->move.crawlDirAxes.get_isDirty() ); //... } //---------------- set -----------------// inline void set_parentGoId( goid_t id_ )noexcept{ this->parentGoId = id_; } inline void set_colliDataFromJsonPtr( const ColliDataFromJson *ptr_ )noexcept{ this->colliDataFromJsonPtr = ptr_; } //---------------- get -----------------// inline bool get_isMoving()const noexcept{ return this->move.get_isMoving(); } // 若为 false,需对齐到 像素 inline const std::set<chunkKey_t> &get_chunkKeysRef()noexcept{ return this->chunkKeys; } inline ColliderType get_colliderType()const noexcept{ return this->colliDataFromJsonPtr->get_colliderType(); } inline goid_t get_parentGoId()const noexcept{ return this->parentGoId; } inline const std::set<goid_t> &get_childGoIdsRef()const noexcept{ return this->childGoIds; } inline size_t get_goUWeight()const noexcept{ return this->goUWeight; } inline Collision &get_collisionRef()noexcept{ tprAssert(this->collisionUPtr); // tmp return *(this->collisionUPtr); } inline const SignInMapEnts_Square &get_signInMapEnts_square_ref()const noexcept{ return SignInMapEnts_Square::get_signInMapEnts_square_ref( this->colliDataFromJsonPtr->get_signInMapEnts_square_type() ); } void debug(); //-- pos sys -- std::function<void(const glm::dvec2 &)> accum_dpos {nullptr}; std::function<void(double)> set_pos_alti {nullptr}; std::function<void(GoAltiRange)> set_pos_lAltiRange {nullptr}; std::function<const glm::dvec2 &()> get_dpos {nullptr}; std::function<double()> get_pos_alti {nullptr}; std::function<GoAltiRange()> get_pos_lAltiRange {nullptr}; //---------------- callback -----------------// // 这些 函数对象 可以被放入 private,然后用 函数调用来 实现绑定... F_GO Awake {nullptr}; //- unused F_GO Start {nullptr}; //- unused F_GO RenderUpdate {nullptr}; //- 每1渲染帧,被引擎调用 F_GO LogicUpdate {nullptr}; //- 每1逻辑帧,被主程序调用 (帧周期未定) F_GO BeAffect {nullptr}; //- 当 本go实例 被外部 施加技能/影响 时,调用的函数 //- 未来可能会添加一个 参数:“被施加技能的类型” // 这个 函数对象,可能会被整合到全新的 Affect 系统中... //-- tmp,未来会被整理.. // 当某一个未绑定时,应将其设置为 nullptr,这样 碰撞检测系统会跳过它 F_AFFECT DoAffect_body {nullptr}; F_AFFECT DoAffect_virtual {nullptr}; F_AFFECT BeAffect_body {nullptr}; // 只有 body 会被登记到 mapent中,所以不存在 BeAffect_virtual //=============== Self Values ===============// goid_t goid; goSpeciesId_t speciesId {0}; goLabelId_t goLabelId {}; GameObjFamily family {GameObjFamily::Major}; double weight {0}; //- go重量 (影响自己是否会被 一个 force 推动) //---- go 状态 ----// GameObjState state {GameObjState::Sleep}; //- 常规状态 GameObjMoveState moveState {GameObjMoveState::AbsFixed}; //- 运动状态 //---- history vals ----// // stone val-state at last render-frame History<NineDirection> actionDirection { NineDirection::Center }; //- 角色 动画朝向 // 此值,仅指 go 在 window坐标系上的 朝向(视觉上看到的朝向) // 而不是在 worldCoord 中的朝向 History<BrokenLvl> brokenLvl { BrokenLvl::Lvl_0 }; // 破损等级,0为完好。 // 当部分go(比如地景)遭到破坏时,此值也会跟着被修改, // 进一步会影响其 外貌 // 未实现 ... //--- Move move; ActionSwitch actionSwitch; //-- 将被 ActionFSM 取代... ActionFSM actionFSM {}; //- 尚未完工... GameObjMeshSet goMeshSet; //PubBinary pubBinary {}; //- 动态变量存储区,此处的变量 可被 engine层/script层 使用 PubBinary2 pubBinary {}; //- 简易版,存储所有元素, 仅用于测试 ... // in future, use DyBinary //InputINS inputINS {}; //- gameKeys 指令组 chunkKey_t currentChunkKey {}; //- 本go 当前所在 chunk key // 在 本go被创建,以及每次move时,被更新 GoFunctorSet pubFunctors {}; // 存储一组,通过 GoFunctorLabel 索引的 任意类型的函数对象 //======== flags ========// bool isTopGo {true}; //- 是否为 顶层 go (有些go只是 其他go 的一部分) // 目前这个值 暂未被使用 ... bool isActive {false}; //- 是否进入激活圈. 未进入激活圈的go,不参与逻辑运算,不被渲染 bool isDirty {false}; //- 是否为 默认go(是否被改写过) //- “默认go” 意味着这个 go没有被游戏改写过。 //- 当它跟着 mapSection 存入硬盘时,会被转换为 go_species 信息。 //- 以便少存储 一份 go实例,节省 硬盘空间。 bool isControlByPlayer {false}; bool isMoveCollide {false}; //- 是否参与 移动碰撞检测, // uiGo 一律为 false。部分 majorGo 也可为 false(游戏世界中的ui元素) // --- // 所有 majorGo 都要登记到 map 上,不管本值是否为 true //======== static ========// static ID_Manager id_manager; private: GameObj( goid_t goid_, size_t goUWeight_ ): goid(goid_), move(*this), actionSwitch(*this), goMeshSet(*this), goUWeight(goUWeight_) {} //-- init --// void init_for_regularGo( const glm::dvec2 &dpos_ ); void init_for_uiGo( const glm::dvec2 &basePointProportion_, const glm::dvec2 &offDPos_ ); //======== vals =======// goid_t parentGoId {NULLID}; // 不管是否为顶层go,都可以有自己的 父go。 std::set<goid_t> childGoIds {}; // 可为空 size_t goUWeight; std::set<chunkKey_t> chunkKeys {}; //- 本go所有 collient 所在的 chunk 合集 // only used for majorGos // 通过 reCollect_chunkKeys() 来更新。 // 在 本go 生成时,以及 每一次移动时,都要更新这个 容器数据 //====== pos sys =====// std::variant< std::monostate, // 当变量为空时,v.index() 返回 0 std::unique_ptr<GameObjPos>, std::unique_ptr<UIAnchor>> goPosVUPtr {}; //----------- pvtBinary -------------// DyBinary pvtBinary {};//- 只存储 具象go类 内部使用的 各种变量 std::unique_ptr<Collision> collisionUPtr {nullptr}; const ColliDataFromJson *colliDataFromJsonPtr {nullptr}; // 一经init,永不改变 }; #endif
turesnake/tprPixelGames
src/Engine/player/gameArchiveId.h
/* * ====================== gameArchiveId.h ======================= * -- tpr -- * CREATE -- 2019.05.01 * MODIFY -- * ---------------------------------------------------------- */ #ifndef TPR_GAME_ARCHIVE_ID_H #define TPR_GAME_ARCHIVE_ID_H //------------------- CPP --------------------// #include <cstdint> // uint8_t using gameArchiveId_t = uint32_t; #endif
turesnake/tprPixelGames
src/Engine/dataBase/dataBase.h
<filename>src/Engine/dataBase/dataBase.h /* * ========================= dataBase.h ========================== * -- tpr -- * CREATE -- 2019.04.29 * MODIFY -- * ---------------------------------------------------------- */ #ifndef TPR_DATA_BASE_H #define TPR_DATA_BASE_H //-------------------- CPP --------------------// #include <unordered_map> //-------------------- Engine --------------------// #include "IntVec.h" #include "DiskGameObj.h" #include "gameArchiveId.h" class GameArchive; namespace db{//---------------- namespace: db ----------------------// void atom_init_dataBase(); void atom_close_dataBase(); //-- table_gameArchive -- void atom_select_all_from_table_gameArchive( std::unordered_map<gameArchiveId_t, GameArchive> &container_ ); void atom_insert_or_replace_to_table_gameArchive( const GameArchive &archive_ ); void atom_writeBack_to_table_gameArchive(); //-- table_goes -- void atom_select_one_from_table_goes( goid_t goid_, DiskGameObj &diskGo_ ); void atom_insert_or_replace_to_table_goes( const DiskGameObj &diskGo_ ); }//----------------------- namespace: db end ----------------------// #endif