Jump to content
  • Advertisement

3dmodelerguy

Member
  • Content count

    1118
  • Joined

  • Last visited

Community Reputation

163 Neutral

About 3dmodelerguy

  • Rank
    Contributor

Personal Information

  • Role
    Programmer
  • Interests
    Programming
  1. 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.
  2. 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.
  3. 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++)?
  4. 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).
  5. 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?
  6. 3dmodelerguy

    Simulating Cursor For Textbox In SDL2

    I'm an idiot (ie. I can't use google well), finally found out about `TTF_SizeText()`.
  7. 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?
  8. 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.
  9. 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.
  10. 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.
  11. 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).
  12. 3dmodelerguy

    Looking for advice on how to proceed with my game

    @Shaarigan Thanks for providing your advice. I don't think I am looking for an all around game creation tool but more so a toolset (or lower-level engine) that provides me a nice programming interface to what I would consider the really bear metal code needed to make a game (like being able to load image / sounds / etc for use, making the draw calls through something like OpenGL, capturing events from input, etc.). For me, Unity, Unreal, Godot, Lumberyard, etc. are the all around game creation tools (which I have not completely excluded from this exploratory process I am doing right now) but the things I am definitely willing to consider more after working with Unity on this project are things like Love2D, MonoGame, etc... (I would not classify those as all around game creation tool but more building blocks for building the blocks need to build a game). The reason I feel it might be worth while to make this exploratory process is that while I have been using Unity for the past 4-5 months on this specific game idea, not a lot of the code is Unity specific. About 80% of the codebase is just plain old C# with no dependencies on Unity. the other 20% are MonoBehaviours that really just connect the functionality of the other code and some UI specific stuff. The code is also in a state I just throw shit at it to just see what works and does not so I am going to have to refactor it a bit (probably completely re-write parts of it) so before I do that, I figured looking at simpler options that might remove a level of complexity that I don't need would be good. Wether I stick with Unity or go with a different option, I will be able to use that codebase as a model (regardless of what language I use going forward). I mean after spending a little time reading up on Lua and about 6ish hours in Love2d, I have a prototype of being able to setup the data for a really large map (40K x 40K tiles) and have it just render a small subsection based on the players position with a section of the game blocked off for UI. Now I know there is still a number of things I need to do here but that is a good chunk of my graphical needs Just because I have spent 4-5 months in Unity does not mean I should stick with it (of course my project requirements also does not mean I should move away from it either). I started with Unity foregoing the processing of look at other lower level options because my original idea that I had would have been able to make use of a lot more features that Unity would have been useful for. It seems to me since that has drastically changed, I might want to look at other options before I am too deep into Unity.
  13. So I have probably spent about 200 - 250 hours in the past 4-5 months prototyping a top down 2D roguelike / survival game (something along the lines of CDDA) in Unity. While everything has been going ok, I am starting to think that most of the tile map managers (assets store ones or the newly built-in one) is just overcomplicating things for my needs. I am also starting to think that Unity itself is overkill. My needs for a tile map manager is really just placing layered tiles on the map of x / y coords and maybe having a few basic brushes and that is about it. With the game being turned based, having actual colliders seems like overkill where just getting the tile and checking manually would work just as well with less overhead. The Unity IDE also seems like overkill since I am hardly in it. I am only in it when building the UI, playing the game, and debugging. Everything game development wise outside of UI creation is done in code since pretty much everything is generated procedurally from data files. If I decide to continue with Unity, I feel like I am going to have to: Setup my own tile map data structure and manager just so I can make things as simple as possible even though that would probably require working with Unity 2D at a lower level which from what I hear is not that great (even with the tile map manager I had, I still had a number of issues with pixel snapping / artifacts and such at the beginning) While I have 80% of the systems prototyped and working at a very basic level, the code would need moderate / major refactoring before I would be comfortable trying to start to build additional features on top of it With this in mind, I figured now would be as good as any time to look at spending a couple of months prototyping the game in another engine or high-level toolset. Again my idea is that since I am not really going to be using a lot of the power than Unity has, there might be something to gain by going with some smaller and simpler engine / high-level toolset but still has the limited features that I need. Instead of trying to figure out what the best game engine is (since that is subjective and does not really exist), I want to get some advice of what game engines / high-level toolsets might fit the requirements that I have. The must haves with no exceptions are: The code that I have to write needs to be managed (and by that I mean I don't want to have to deal with memory management because this is no doubt I will shoot myself in the foot, leg, hand, arm, etc. if I have to deal with that). I want all the lower level APIs (like calling OpenGL, DirectX, OpenAL, etc. directly) to be dealt with under the covers so that I can easily draw stuff, load sprites, play sounds, etc. using the engine's / high-level toolset's API. Need to be able to develop on Mac Need to be able to deploy to Windows / Mac Needs to have the following features: A true 2D engine that is designed to work ix X / Y and pixels (not a 2D game in a 3D engine like Unity) A Sound API An Assets Loading Pipeline (it should be relatively easy to load up a sprite sheet, slice it into is sprites, etc. through code) An Input Management System Now at the very top of my really nice to haves would be: Has easy support for ECS (I have recently looked into this since I know Unity is moving towards that and from what I have researched, it looks like a very interesting way to structure code for reusability that fits more with me than traditional OOP) Has an active community and helpful community Has a decent UI system, stuff like: Being able to display a list of UI "elements" of any number Being able to have flexible container boxes (kinda like css flexboxes) Being able to display images / sprites / icons in the UI Being able to overlay the UI anywhere on the screen And then at the bottom of the nice to have list would be: Is being actively developed / maintained (it does not need multiple commits every day and releases every month but it should not have nothing for months on end) Built-in / external module for 2D AStar Path Finding Additional engine features like Lighting, Physics, etc. (again, I have no need for this stuff however if available, I would probably be able to make some small use of it) Game logic is written in a lighter weight language or functional language (like Lua, JavaScript, etc.) Has no custom Editor / IDE (this is because I prefer code and I don't want the "why are you trying to use code instead of the editor" response like I have often gotten with Unity when I asking questions). For the specific points of my game that I would want to take into account when deciding on another engine / high-level toolset to prototype in, they would be: With the game being turned based, it is going to work off of a global game action units system that increase when they player perform actions and all other entities would listen on and perform actions based on the game action units that changed since they last update (which will probably being at least in the 100's of entities, I can even see if maybe reaching 1000+) I want to have a near infinite world that is procedurally generated (which I would imagine would be able to be done by storing the map is small chunks of like 16x16, 32x32, etc and then just loading / unload those chunks that are in a certain range of the player as they move). I want to have a relatively large area of simulated world. Obviously I can't simulation the 10s of 1000s of entities that would be in the entire game world but I would like to try for what CDDA does with it reality bubble which is 132 x 132 (which is also 17424 tiles that would be rendered at any given time) and simulate the entities in there (and simulate I mean stuff like npcs / enemies moving, items decaying / rotting, building tiles burning, etc.). Outside of these points, everything else in my game (like quests, npcs, enemies, items, skills, stats, AStar pathing finding, crafting building, etc.) I think should be able to work in any game engine. Right now Love2D is at the top of my list of engines / high-level toolsets to try. It uses Lua as the scripting language which also has a number of ECS libraries that I could try out. While I would like to use a lighter weight language like Lua, my top concern with that is performance (especially related to point #1 + #3 with what how much I am going to want to simulate in the game) but from what I hear, LuaJIT, which Love2D uses, can provide near c performance so... I would like to get people opinions on Love2D related to all the points above as well as any other engines / high-level toolsets that at least fits the must haves from an engine / toolset perspective and will support the performance based features of the game that I mentioned. I plan on trying to get a character to move on a map in each engine / high-level toolset that should be able to support what I need and they make a decision of which to take further into the prototype.
  14. @Nypyren So I remember at one point someone telling me (or reading it somewhere) to avoid using events for game dev because of performance. Not sure if that is true, if I misunderstand, or just old advice (I think it has been a while since that) but that is why I did not go the route of events for this. Are events performance efficient for game system communications? The game I am building is along turn based (though a player could perform 15-25 moves per second) so maybe performance with this kind of code is not as important as it was not run very often.
  15. I am asking this just to get a sense of how people think about this problem as I don’t think there is a “right” answer and they way I think about code structure for my day job (which is highly functional / immutable based JavaScript code for frontend applications) don’t quite fit into game development I think. This question came up from the fact that I added a simple quest system prototype to my game and one of the requirements for a quest could be collect X number of items. The original way I implemented this was that in order to see if a quest was completable, you would have to pass the quest the inventory object of the player and then it could check the items and see if the player meets the requirements. Then I wanted to add a message in the activity log (this is a turn based game) when the player reached the item requirements however I could not do that, at least easily, with how the quest item requirement was designed so I instead move the coupling of the quest system and inventory system so that the inventory system would update the quest when an item iwas added / removed which allowed me to easily add the activity log message that I wanted to. This might be a stupid question however I was wondering what peoples process might be when figuring out how / where to couple game systems together? Maybe it is just something the comes to light when you figuring out how the game system are going to work (and maybe I need to do more forethought about my game systems) but I figured I would ask to see if I could gain some insight about this from other people.
  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!