Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: How to organise data? And what about dinamic/static memory?  (Read 1914 times)

0 Members and 1 Guest are viewing this topic.

Gaaza

  • Newbie
  • *
  • Posts: 6
    • View Profile
Hi,

Sorry if this thread doesn't suit the topic of the forum, but I have not seen any better place to post it. Maybe these kind of topic is too general, so tell me if it is the case.

I have been working on a game, which now I have debugged collision and it is working, I want to let the player to shoot an arrow or a bullet.
As a beginner in C++ I don't now how to do that, but I can wonder some methods:

1. Create one or more static objects "Arrow" inside class "Player", which are set to visible and set to a position (and some properties more) when the player attacks.
2. Create a dinamic object (through unique_ptr) and wonder how not to destroy it when I went out of scope there I created it (saving status and loading status in the next call)
3. Investigate threads and how to launch these objects with them.

Another thing about I am thinking is if it is possible to run animations, like when the player dies, through threads, due these animations don't interact with the player (I think enemies are harder to program into a thread because they have to interact with the player, arrows, etc).

Thank yo for your help!

Arcade

  • Full Member
  • ***
  • Posts: 230
    • View Profile
Re: How to organise data? And what about dinamic/static memory?
« Reply #1 on: July 27, 2018, 03:59:07 pm »
In general these are game design questions that you would have to solve even if you were using a different library from SFML. These forums tend to be more focused on SFML directly, so you may not get the best help here.

Having said that, here are some thoughts:

  • Since you are a beginner in C++ I would recommend not bothering with threads for anything. They add a lot of complexity and it is very easy to introduce hard to debug race conditions and other problems. You don't need threads to solve the types of problems you're facing.
  • look up how to use std::vector. It may hep you with your problem of holding on to multiple arrows or multiple frames of an animation. For example, perhaps your player class could have a std::vector member variable for holding in-flight arrows. You could add more arrows to the vector as they are shot and remove arrows as they hit enemies. This is just one possibility of many.
  • Why not try to learn game design by following some examples. You could take a look at the books listed on the Learn SFML page.


Gaaza

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: How to organise data? And what about dinamic/static memory?
« Reply #2 on: July 27, 2018, 08:10:02 pm »
Thank you for your help!

About threads, I have been thinking and you are right, maybe I want to learn too much at the same time, when I only know the base of C++.
About "bullets", I asked because I had the strange feel that they had to be dinamic memory through pointers, but you are right one more time, it is easier to avoid pointers and manage them through containers. I think Stroustrup and collegues are driving C++ into that direction: avoid traditional pointers and try to manage memory in automatic mode (vectors, maps, sets, unique_ptr, shared_ptr, etc).
I purchased two books and tried to follow them: "SFML Game Development" and "SFML Game Development by example". I think they are great books and I have improved my code a lot, but they turned too hard for me, so now I am following them sometimes when I am looking for very concrete help. I think they are in a "professional" or "semi-professional" level (maybe I am wrong) but certainly I like them.

About game designing, it is probably not the best place to ask due the forum is oriented to SFML and not general game design as you said. I will consider it in the future  ;)

Ralf Pi

  • Newbie
  • *
  • Posts: 1
    • View Profile
Re: How to organise data? And what about dinamic/static memory?
« Reply #3 on: August 24, 2022, 04:45:40 pm »
In general these are game design questions that you would have to solve even if you were using a different library from SFML. These forums tend to be more focused on SFML directly, so you may not get the best help here.

Having said that, here are some thoughts:

  • Since you are a beginner in C++ I would recommend not bothering with threads for anything. They add a lot of complexity and it is very easy to introduce hard to debug race conditions and other problems. You don't need threads to solve the types of problems you're facing.
  • look up how to use std::vector. It may hep you with your problem of holding on to multiple arrows or multiple frames of an animation. For example, perhaps your player class could have a std::vector member variable for holding in-flight arrows. You could add more arrows to the vector as they are shot and remove arrows as they hit enemies. This is just one possibility of many.
  • Why not try to learn game design by following some examples. You could take a look at the books listed on the Learn SFML page.
What sources to use? A while ago, I tried to learn how to do data enrichment api in a SQL database. The upgrade process is more complicated than the creation of the database. After a bit of research, I found the instructions to delete the obsolete data. I got stuck when it came to add and edit the data. Google offers many sources that pretend to explain how to do these two processes in a SQL database. When in fact, all explanations are far from being relevant to my issues. I was thinking maybe someone here would like to explain the adding/editing processes.
« Last Edit: September 19, 2022, 02:19:26 pm by Ralf Pi »

 

anything