Jump to content
  • Advertisement

3dmodelerguy

Member
  • Content Count

    1122
  • Joined

  • Last visited

Community Reputation

166 Neutral

About 3dmodelerguy

  • Rank
    Contributor

Personal Information

  • Role
    Programmer
  • Interests
    Programming
  1. Thanks for the advice. For the time being I decided to go with a premade solution (https://www.assetstore.unity3d.com/en/#!/content/26617). I don't have a deep enough knowledge of the math that would be required building that kind of system myself nor do I have the desire to push myself to learn that kind of math right now (this just being a side project, I would rather focus of the areas of game development that are more interesting to me where I don't mind using my free time at doing). The library has everything I would absolutely need and most of what I would ideally want. If this prototype gets further than most of my other prototypes I might invest more time into the movement aspect of the game myself (and I will already have a large set of script to be able to use as reference now) but I think trying to focus on that now before I have a bunch of the game play functionality working at a basic level would be premature for me.
  2. So I am trying to prototype a 2D platformer like game in Unity and trying to figure out the best method that I should be investigating for controlling the player character. I see generally 2 different ways to handle this which is either using Rigidbody2D or using raycasts. The list of things that I am looking to do right now are: has some sort of gravity like effect moving side to side jumping double jumping being able to walking up slopes of a certain angle (but prevent it after a certain angle and have the user slide down if they are on that angle or larger) be able to hang off the edge and pull up I sure some things might come up later in development if I get that far but these are what I want to get working at least at a very basic level before I move on from the character controller for the prototype (if you watch this video for about 15 - 20 seconds, you will see generally most of the functionality I am looking to achieve: https://www.youtube.com/watch?v=6rzTnx6IHqM&start=375). Now I started with the Rigidbody2D since I do want to have some level of gravity in the game (not just the player but items, enemy, etc.) and I can get the first 4 working pretty easy but the 5th is more troublesome (and have not gotten to the 6th). I can move up angles (I am setting Rigidbody2D.velocity for movement as it seems to be the most recommended) but for example if I am walking up an angle and then stop, my character jumps up a little (I am guess because of the forward velocity that is has when I stop applying hortizontal velocity for moving side to side, there is still extra vertical velocity). So I have 2 questions: Should I be looking at Rigidbody2D or manual raycasts? Either way that you recommend going, do you have any resources that you would recommend looking at for reference (video tutorials, articles, etc.)?
  3. For reference I am use Unity as my game engine and the A* Pathfinding Project for path finding as there is no chance I would be able to create anything close to as performant as that in any reasonable amount of time. So I am looking to build a game that is going to have a very similar style as Prison Architect / Rim World / SimAirport / etc. One of the things that I assume is going to effect performance is path finding. Decisions about the game I have already made that I think relate to this are: 1. While I am going to be using Colliders, all of them will be trigger colliders so everything can pass through each other and I will not be use physics for anything else as it has no relevance for my game 2. I am going to want to have a soft cap at the map size being 300x300 (90,000 tiles), I might allow bigger sizes but do something like Rim World does in warning the player about possible side effect (whether it be performance or gameplay) 3. The map will be somewhat dynamic in that the user will be able to build / gather stuff from the map but outside of that, it should not change very much Now I am going to build my game around the idea that users would be in control of no more than 50 pawns at any given time (which is something I can probably enforce through the game play) but I am also going to want to have number other pawns that are AI controlled on the map (NPCs, animals, etc.) that would also need path finding enabled. Now I did a basic test in which I have X number of pawns pick a random location in the 300 x 300 map. move towards it, and then change the location every 3-5 seconds. My initial test was pretty slow (not surprising as I was calculating the path every frame for each pawn) so I decided to cache the calculated path results and only update it ever 2 seconds which got me: 100 pawns: 250 - 450 FPS 150 pawns: 160 - 300 FPS 200 pawns: 90 - 150 FPS 250 pawns: 50 - 100 FPS There is very little extra happening in the game outside of rendering the tilemap. I would imagine the most pawns on the map at a given time that need path finding might be a 1000 (and I would probably be able to make due with like 500 - 600). Now obviously I would not need all the pawn to be calculation paths every 2 seconds nor would they need to be calculating paths that are so long but even at a 5 second path refresh rate and paths that are up to 10 tiles long, I am still only able to get to about 400 pawns before I start to see some big performance issues. The issue with reducing the refresh rate is that there are going to be cases where maybe a wall is built before the pawns path is refreshed having them walk through the wall but not sure if there is a clean way to update the path only when needed. I am sure when I don't run the game in the Unity editor I will see increase performance but I am just trying to figure out what things I could be doing to make sure path finding is as smaller of a performance hit as possible as there is a lot of other simulation stuff I am going to want to run on top of the path finding.
  4. So I am using an entity component system for the first time and while I like how it organizes the code, I am having issue understanding how to go about 1 thing at the moment. In case this matters, the game in a 2D turn based rogue like game. So with the ECS, the player is just like any other entity and right now it does not have any component on it that is unique to the player. The issue is that I find that there are multiple use cases where I want to have access to the player's specific entity either outside of the ECS or within the context of a system that works on different entities. I will try to give a couple of concrete examples. For example I have an inventory UI screen that is outside of the ECS but needs access to the player's inventory (to show the items). Another example would be the enemy path finding system which would need access to the player's locations (in order to both know if the player is within aggro range and to know the location to path find to). Another would be a world loot system that needs access to the players location (as only items within a certain range of the player should be rendered). Most generic stuff I have read says that Entities should just hold components and nothing else. Now I generally don't apply patterns dogmatically if I think there is a valid use case to diverge slightly and this is one of those cases to me. What I am leaning towards is having a unique label that can be placed on the entity or have it null if not needed. This seems to be an edge as the only thing I think I am going to need this unique label for is the entity of the player (but who knows, other use cases might show up later). Does this seem like an unreasonable way to implement an ECS? I am open to the idea that there might be other ways to handle the use cases where I need access to the player's specific entity but I can't think of one right now.
  5. 3dmodelerguy

    Major Performance Issues with yaml-cpp

    So by following some advice on stackoverflow, by adding this as a preprocessor defination: _HAS_ITERATOR_DEBUGGING=0 and setting Basic Runtime Checks to Default it got the code down to running in just over 1 seconds. I guess I will leave it at that for time time being I might look at doing this at some point.
  6. 3dmodelerguy

    Major Performance Issues with yaml-cpp

    I am not trying to use YAML because it is hip or whatever but that my game is going to involve a lot of data that is going to be loading from files and I want to make writing (manually) / reading those files as clean as possible and YAML in my opinion has the best combination of readability and functionality. This might be something I want to do later on however I think I am going to what the option to have most of the data that can be in text have the option to be stored in text just for easier debug-ability. This is true and something I might do later as well on but I think using a library should be easier for right now verse implementing a custom parser that implements only the features I need (which I would agree is probably a pretty small subset of the full YAML spec). As to my performance issue, it seems the main issue is with running the code in debug mode (using default Visual Studio debug settings). In release mode the file writes in about 0.15 seconds (instead of about 7 seconds) and memory spikes to only 36MB (instead of 108MB). I thought it was good practice to always run code in debug mode when writing code however this kinda of performance loss seems bad. I am not sure if there are some tweaks to I can make to the debug mode settings to prevent this kinda of performance hit while still retaining a lot of the benefit of debug mode.
  7. So I have been playing around with yaml-cpp as I want to use YAML for most of my game data files however I am running into some pretty big performance issues and not sure if it is something I am doing or the library itself. I created this code in order to test a moderately sized file: Player newPlayer = Player(); newPlayer.name = "new player"; newPlayer.maximumHealth = 1000; newPlayer.currentHealth = 1; Inventory newInventory; newInventory.maximumWeight = 10.9f; for (int z = 0; z < 10000; z++) { InventoryItem* newItem = new InventoryItem(); newItem->name = "Stone"; newItem->baseValue = 1; newItem->weight = 0.1f; newInventory.items.push_back(newItem); } YAML::Node newSavedGame; newSavedGame["player"] = newPlayer; newSavedGame["inventory"] = newInventory; This is where I ran into my first issue, memory consumption. Before I added this code, the memory usage of my game was about 22MB. After I added everything expect the YAML::Node stuff, it went up to 23MB, so far nothing unexpected. Then when I added the YAML::Node and added data to it, the memory went up to 108MB. I am not sure why when I add the class instance it only adds like 1MB of memory but then copying that data to a YAML:Node instance, it take another 85MB of memory. So putting that issue aside, I want want to test the performance of writing out the files. the initial attempt looked like this: void YamlUtility::saveAsFile(YAML::Node node, std::string filePath) { std::ofstream myfile; myfile.open(filePath); myfile << node << std::endl; myfile.close(); } To write out the file (that ends up to be about 570KB), it took about 8 seconds to do that. That seems really slow to me. After read the documentation a little more I decide to try a different route using the YAML::Emitter, the implemntation looked like this: static void buildYamlManually(std::ofstream& file, YAML::Node node) { YAML::Emitter out; out << YAML::BeginMap << YAML::Key << "player" << YAML::Value << YAML::BeginMap << YAML::Key << "name" << YAML::Value << node["player"]["name"].as<std::string>() << YAML::Key << "maximumHealth" << YAML::Value << node["player"]["maximumHealth"].as<int>() << YAML::Key << "currentHealth" << YAML::Value << node["player"]["currentHealth"].as<int>() << YAML::EndMap; out << YAML::BeginSeq; std::vector<InventoryItem*> items = node["inventory"]["items"].as<std::vector<InventoryItem*>>(); for (InventoryItem* const value : items) { out << YAML::BeginMap << YAML::Key << "name" << YAML::Value << value->name << YAML::Key << "baseValue" << YAML::Value << value->baseValue << YAML::Key << "weight" << YAML::Value << value->weight << YAML::EndMap; } out << YAML::EndSeq; out << YAML::EndMap; file << out.c_str() << std::endl; } While this did seem to improve the speed, it was still take about 7 seconds instead of 8 seconds. Since it has been a while since I used C++ and was not sure if this was normal, I decided to for testing just write a simple method to manually generate the YAMLin this use case, that looked something like this: static void buildYamlManually(std::ofstream& file, SavedGame savedGame) { file << "player: \n" << " name: " << savedGame.player.name << "\n maximumHealth: " << savedGame.player.maximumHealth << "\n currentHealth: " << savedGame.player.currentHealth << "\ninventory:" << "\n maximumWeight: " << savedGame.inventory.maximumWeight << "\n items:"; for (InventoryItem* const value : savedGame.inventory.items) { file << "\n - name: " << value->name << "\n baseValue: " << value->baseValue << "\n weight: " << value->weight; } } This wrote the same file and it took about 0.15 seconds which seemed a lot more to what I was expecting. While I would expect some overhead in using yaml-cpp to manage and write out YAML files, it consuming 70X+ the amount of memory and it being 40X+ slower in writing files seems really bad. I am not sure if I am doing something wrong with how I am using yaml-cpp that would be causing this issue or maybe it was never design to handle large files but was just wondering if anyone has any insight on what might be happening here (or an alternative to dealing with YAMLin C++)?
  8. 3dmodelerguy

    using yaml-cpp with pointers in C++

    @DaBono Thanks for pointing out what was happening here as it now makes sense why this was my issue (I guess I should have looked at the libraries code closer).
  9. So I am trying to using Yaml as my game data files (mainly because it support comments, is a bit easier to read than JSON, and I am going to be working in these files a lot) with C++ and yaml-cpp (https://github.com/jbeder/yaml-cpp) seems like the most popular library for dealing with it however I am running into an issue when using pointers. Here is my code: struct InventoryItem { std::string name; int baseValue; float weight; }; struct Inventory { float maximumWeight; std::vector<InventoryItem*> items; }; namespace YAML { template <> struct convert<InventoryItem*> { static Node encode(const InventoryItem* inventoryItem) { Node node; node["name"] = inventoryItem->name; node["baseValue"] = inventoryItem->baseValue; node["weight"] = inventoryItem->weight; return node; } static bool decode(const Node& node, InventoryItem* inventoryItem) { // @todo validation inventoryItem->name = node["name"].as<std::string>(); inventoryItem->baseValue = node["baseValue"].as<int>(); inventoryItem->weight = node["weight"].as<float>(); return true; } }; template <> struct convert<Inventory> { static Node encode(const Inventory& inventory) { Node node; node["maximumWeight"] = inventory.maximumWeight; node["items"] = inventory.items; return node; } static bool decode(const Node& node, Inventory& inventory) { // @todo validation inventory.maximumWeight = node["maximumWeight"].as<float>(); inventory.items = node["items"].as<std::vector<InventoryItem*>>(); return true; } }; } if I just did `std::vector<InventoryItem> items` and had the encode / decode use `InventoryItem& inventoryItem` everything works fine however when I use the code above that has it as a pointer, I get the following error from code that is part of the yaml-cpp library: impl.h(123): error C4700: uninitialized local variable 't' used The code with the error is: template <typename T> struct as_if<T, void> { explicit as_if(const Node& node_) : node(node_) {} const Node& node; T operator()() const { if (!node.m_pNode) throw TypedBadConversion<T>(node.Mark()); T t; if (convert<T>::decode(node, t)) // NOTE: THIS IS THE LINE THE COMPILER ERROR IS REFERENCING return t; throw TypedBadConversion<T>(node.Mark()); } }; With my relative lack of experience in C++ and not being able to find any documentation for yaml-cpp using pointers, I am not exactly sure what is wrong with my code. Anyone have any ideas what I need to change with my code?
  10. 3dmodelerguy

    Simulating Cursor For Textbox In SDL2

    I'm an idiot (ie. I can't use google well), finally found out about `TTF_SizeText()`.
  11. So I have this code to create a textbox ui element with SDL2 and for the most part it works: #include <iostream> #include "TextboxUi.hpp" #include "../Engine/Text.hpp"; #include "../Utility/SdlUtility.hpp"; #include "../Engine/Game.hpp"; TextboxUi::TextboxUi(int x, int y, int width, int height, SDL_Color backgroundColor, SDL_Color textColor) { _background = {x, y, width, height}; _backgroundColor = backgroundColor; _textColor = textColor; } void TextboxUi::setValue(std::string value) { _value = value; } void TextboxUi::handleInput(SDL_Event &event) { switch (event.type) { case SDL_TEXTINPUT: { if (_isActive) { _value += event.text.text; _cursorPosition += 1; } break; } case SDL_TEXTEDITING: { break; } case SDL_KEYUP: { switch (event.key.keysym.sym) { case SDLK_BACKSPACE: if (_value.size() == 0) { break; } _cursorPosition -= 1; _value.erase(_cursorPosition, 1); break; case SDLK_s: { if (!_isActive) { _isActive = true; } break; } case SDLK_LEFT: { if (_cursorPosition == 0) { break; } _cursorPosition -= 1; break; } case SDLK_RIGHT: { if (_cursorPosition == _value.size()) { break; } _cursorPosition += 1; break; } case SDLK_ESCAPE: _isActive = false; _value = ""; break; default: break; } break; } default: break; } } void TextboxUi::enable() { _isActive = true; } void TextboxUi::disable() { _isActive = false; } void TextboxUi::draw(SDL_Renderer* renderer) { SdlUtility::setRenderDrawColor(Game::renderer, _backgroundColor); SDL_RenderFillRect(Game::renderer, &_background); // if there is no text Text would fail to create the surface and texture (not quite sure why) if (_value.size() == 0) { return; } Text text = Text("Assets/Fonts/Vera.ttf", 12, _value, _textColor); text.display(_background.x + 5, _background.y + 2); // @todo implement visual for text cursor } The one last thing I want to do before I call this textbox done for the time being is try to figure out how to simulate a cursor. At this point just getting a solid cursor would be final (though ultimately I would like to have it blinking. I have the cursor position so I know between which characters the cursor should be however I am not sure how to calculate that. Is there a way to calculate the width of a given string without actually rendering said sting to the screen with SDL2 / SDL2_ttf?
  12. 3dmodelerguy

    A few questions about some c++ code

    @AthosVG Thanks for provide a really nice detailed explanation, it did help clear up some confusion I had @Alberth Would you have any good books that you would recommended (ideally something updated to c++17)? I would ideally like a book that skips that very basic of programming that is common to most language (like variables, control flow, function basics, etc) and really focuses on the unique C++ stuff and more advance C++ topics.
  13. So in the few different tutorials that I have seen for using C++ / SDL, the implementation of the camera does not effect how the player is rendered but how the the rest of the world is rendered. Instead of changing the position / offset of where the player is rendered, you change the position / offset of where the map and other entities are renderer. Out of curiosity, is this the standard (or maybe only) way of doing things when working with lower level code like C++ / SDL? While it makes logical sense to me, my experience in game dev has always been high level abstractions (game engines like Unity or even libraries like Love) so it just feels wrong but maybe all of those engines / tools do it the same way and the abstraction they provide just hides that fact.
  14. A few questions about some c++ code So I am starting to get back into c++ after about 12 - 14 years away from it (and even back then, my level of knowledge was maybe a little above beginner) to do some game / SDL programming. I was following a tutorial to get at least a basic starting point for an entity component system and it works however there was some code that I don't quite understand even after looking around little. First pice of code is: T* component(new T(std::forward<TArguments>(arguments)...)); This seems to be assigning the `component` with the results of what is in the parentheses though normally I would expect this: T* component = new T(std::forward<TArguments>(arguments)...); Is this just syntax preference or does the compiler do something different with the parentheses (it is weird to me as when I see that, I think it is a function call)? The second piece of code I think I understand the general idea of what it is doing but some of the specific are escaping me: template <typename T, typename... TArguments> T& Entity::addComponent(TArguments&&... arguments) { T* component = new T(std::forward<TArguments>(arguments)...); So from my understanding, the first line would basically take this: entity->addComponent<TransformComponent, int, int, int, int>(x, y, width, height); and take of the first item in the template and assign the to T and then "group" (not sure the correct term) the rest of the items as a collection of some sort and then the `...` on the second line would group the arguments (that would need to match the template group) that were passed in. Then the third line is effectively converting the template / passed in arguments to be called like this: TransformComponent* component = new TransformComponent(x, y, width, height); The parts that are a bit confusing to me is first the `&&`. From what I have read (from stack overflow), that symbol means rvalue reference or reference to an argument that is about to be destroyed. Not quite sure what it means by it about to be destroyed. The second part, which I think related to using `&&`, is the `std::forward<TArguments>`. The explainations that I have found so far as are bit confusing to me. I will continue to try to find the answer to these confusions but I though maybe someone here might have an explanation that might make more sense to me. I would also consider it quite possible that there is some prerequisite knowledge that I might not have (I mean I think I have a decent understanding of pointers and references) so if there is other stuff I should looking into, that would be great too.
  15. So something that I am interested in learning more about is using the Entity Component System pattern for structuring my code and was wondering if anyone had any recommendations of tutorials on this subject? Any kind of tutorial would be good but ideally I prefer video as I generally learn better that way (it being in Lua would be a plus since that is the language I would be implementing this in).
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!