• 12
• 12
• 9
• 10
• 13
• ### Similar Content

• By dgi
Hey all ,
For a few days I'm trying to solve some problems with my engine's memory management.Basically what is have is a custom heap with pre allocated memory.Every block has a header and so on.I decided to leave it like that(not cache friendly) because my model is that every block will be large and I will have a pool allocators and stack allocators dealing with those blocks internally. So far so good I figure out how to place my per scene resources . There is one thing that I really don't know how to do and thats dealing with containers.What kind of allocation strategy to use here.
If I use vector for my scene objects(entities , cameras , particle emitters .. ) I will fragment my custom heap if I do it in a standard way , adding and removing objects will cause a lot of reallocations . If I use a linked list this will not fragment the memory but it's not cache friendly.I guess if a reserve large amount of memory for those vectors it will work but then I will waste a lot memory.I was thinking for some sort of mix between a vector and a linked list , where you have block of memory that can contain lets say 40 items and if you go over that number a new one will be created and re location of the data would not be needed.There would be some cache misses but it will reduce the fragmentation.

How you guys deal with that ? Do you just reserve a lot data ?

dgi
• By Hermetix
I am trying to setup the custom wizard for making a 3ds MAX 2018 plug-in (to export a character animation data), but I can't locate the wizard file folder to put the .vsz file in. In the 3ds MAX 2018 docs, it only mentions where the folder is in VS 2015 (VC/vcprojects). It's a VC++ project, but I don't see any folder in VC for the wizard files. I'm using VS 2017 update 15.5.6 Enterprise, and the folders in VC are: Auxiliary, Redist and Tools.

Thanks.
• By KarimIO
Hey guys! Three questions about uniform buffers:
1) Is there a benefit to Vulkan and DirectX's Shader State for the Constant/Uniform Buffer? In these APIs, and NOT in OpenGL, you must set which shader is going to take each buffer. Why is this? For allowing more slots?
2) I'm building an wrapper over these graphics APIs, and was wondering how to handle passing parameters. In addition, I used my own json format to describe material formats and shader formats. In this, I can describe which shaders get what uniform buffers. I was thinking of moving to support ShaderLab (Unity's shader format) instead, as this would allow people to jump over easily enough and ease up the learning curve. But ShaderLab does not support multiple Uniform Buffers at all, as I can tell, let alone what parameters go where.
So to fix this, I was just going to send all Uniform Buffers to all shaders. Is this that big of a problem?
3) Do you have any references on how to organize material uniform buffers? I may be optimizing too early, but I've seen people say what a toll this can take.
• By abarnes
Hello All!
I am currently pursuing a degree in video game programming, so far I have completed an intro to programming course and object oriented programming course. Both were taught using C++ as the programming langauge which I know is very popular for game development, but in these classes we do not actually do any game development. I would like to start to build my skills with C++ for game development as that is a common required thing for a job and am looking for ways to do this. Any recommendations such as books to read or youtube videos to watch will be greatly appreciated!
• By Orella
I'm having problems rotating GameObjects in my engine. I'm trying to rotate in 2 ways.
I'm using MathGeoLib to calculate maths in the engine.
First way: Rotates correctly around axis but if I want to rotate back, if I don't do it following the inverse order then rotation doesn't work properly.
e.g:
Rotate X axis 50 degrees, Rotate Y axis 30 degrees -> Rotate Y axis -50 degrees, Rotate X axis -30 degrees. Works.
Rotate X axis 50 degrees, Rotate Y axis 30 degrees -> Rotate X axis -50 degrees, Rotate Y axis -30 degrees. Doesn't.

Code:
void ComponentTransform::SetRotation(float3 euler_rotation) { float3 diff = euler_rotation - editor_rotation; editor_rotation = euler_rotation; math::Quat mod = math::Quat::FromEulerXYZ(diff.x * DEGTORAD, diff.y * DEGTORAD, diff.z * DEGTORAD); quat_rotation = quat_rotation * mod; UpdateMatrix();  } Second way: Starts rotating good around axis but after rotating some times, then it stops to rotate correctly around axis, but if I rotate it back regardless of the rotation order it works, not like the first way.

Code:
void ComponentTransform::SetRotation(float3 euler_rotation) { editor_rotation = euler_rotation; quat_rotation = math::Quat::FromEulerXYZ(euler_rotation.x * DEGTORAD, euler_rotation.y * DEGTORAD, euler_rotation.z * DEGTORAD); UpdateMatrix();  }
Rest of code:
#define DEGTORAD 0.0174532925199432957f void ComponentTransform::UpdateMatrix() { if (!this->GetGameObject()->IsParent()) { //Get parent transform component ComponentTransform* parent_transform = (ComponentTransform*)this->GetGameObject()->GetParent()->GetComponent(Component::CompTransform); //Create matrix from position, rotation(quaternion) and scale transform_matrix = math::float4x4::FromTRS(position, quat_rotation, scale); //Multiply the object transform by parent transform transform_matrix = parent_transform->transform_matrix * transform_matrix; //If object have childs, call this function in childs objects for (std::list<GameObject*>::iterator it = this->GetGameObject()->childs.begin(); it != this->GetGameObject()->childs.end(); it++) { ComponentTransform* child_transform = (ComponentTransform*)(*it)->GetComponent(Component::CompTransform); child_transform->UpdateMatrix(); } } else { //Create matrix from position, rotation(quaternion) and scale transform_matrix = math::float4x4::FromTRS(position, quat_rotation, scale); //If object have childs, call this function in childs objects for (std::list<GameObject*>::iterator it = this->GetGameObject()->childs.begin(); it != this->GetGameObject()->childs.end(); it++) { ComponentTransform* child_transform = (ComponentTransform*)(*it)->GetComponent(Component::CompTransform); child_transform->UpdateMatrix(); } } } MathGeoLib: Quat MUST_USE_RESULT Quat::FromEulerXYZ(float x, float y, float z) { return (Quat::RotateX(x) * Quat::RotateY(y) * Quat::RotateZ(z)).Normalized(); } Quat MUST_USE_RESULT Quat::RotateX(float angle) { return Quat(float3(1,0,0), angle); } Quat MUST_USE_RESULT Quat::RotateY(float angle) { return Quat(float3(0,1,0), angle); } Quat MUST_USE_RESULT Quat::RotateZ(float angle) { return Quat(float3(0,0,1), angle); } Quat(const float3 &rotationAxis, float rotationAngleRadians) { SetFromAxisAngle(rotationAxis, rotationAngleRadians); } void Quat::SetFromAxisAngle(const float3 &axis, float angle) { assume1(axis.IsNormalized(), axis); assume1(MATH_NS::IsFinite(angle), angle); float sinz, cosz; SinCos(angle*0.5f, sinz, cosz); x = axis.x * sinz; y = axis.y * sinz; z = axis.z * sinz; w = cosz; } Any help?
Thanks.

# Circular inclusion problem

## Recommended Posts

I think I am having the problem mentioned in the title, but I can't be sure of it as well...

Got 3 classes, GameMode, Entity, Paddle.

Paddle Inherit from Entity, and both Paddle and Entity need to #include "GameMode.h" in order to pass down the constructor a GameMode* and store it inside of every Entity.

I pretty much forward declared everything inside everything else but stuff just won't compile, the error I am getting is C2504 "Entity: base class undefined" .

I'll paste below the .h and .cpp for the Entity class, and only .h for the other two. Can someone tell me what am I doing wrong?

Entity.h

#pragma once
#include "SDL2\SDL.h"
#include "GameMode.h"
#include "Utility.h"
using namespace util;

class GameMode;
enum class PivotMode: Uint8 {CENTER,TOP_LEFT};

class Entity
{
protected://variables
float XCenter;
float YCenter;
SDL_Rect CollisionBox;
SDL_Texture* Sprite;
GameMode* Game;
SDL_Renderer* Renderer;

public://constructors
Entity(GameMode* gameRef, PivotMode inputMode, int x, int y, std::string path);
virtual ~Entity();
Entity(const Entity&) = delete;
Entity& operator=(const Entity&) = delete;
Entity(Entity&&) = delete;
Entity& operator=(Entity&&) = delete;

public://methods
virtual void Update(float deltaTime) = 0;
virtual void Draw(float interpolation) = 0;

private://methods
SDL_Texture* RequestTexture(std::string path)const;
void SetCollisionBox(int x, int y, PivotMode InputMode);
};


Entity.cpp

#include "Entity.h"

Entity::Entity(GameMode* gameRef, PivotMode inputMode, int x, int y, std::string path)
:Game{ gameRef }, XCenter{ static_cast<float>(x) }, YCenter{ static_cast<float>(y) }
{
if (Game) { Renderer = Game->GetRenderer(); }
Sprite = RequestTexture(path);

if (Sprite)
{ SetCollisionBox(x, y, inputMode); }
}

Entity::~Entity()
{
}

SDL_Texture* Entity::RequestTexture(std::string path)const
{
if (Game->IsRunning())
{
return Game->RequestTexture(path);
}
return nullptr;
}

void Entity::SetCollisionBox(int x, int y, PivotMode InputMode)
{
SDL_QueryTexture(Sprite, nullptr, nullptr, &CollisionBox.w, &CollisionBox.h);

switch (InputMode)
{
case PivotMode::CENTER:
{
CollisionBox.x = x - CollisionBox.w / 2;
CollisionBox.y = y - CollisionBox.h / 2;
XCenter = static_cast<float>(x);
YCenter = static_cast<float>(y);
}break;
case PivotMode::TOP_LEFT:
{
CollisionBox.x = x;
CollisionBox.y = y;
XCenter = static_cast<float>(x) + CollisionBox.w / 2;
YCenter = static_cast<float>(y) + CollisionBox.h / 2;
}break;
}
}

#pragma once
#include "Entity.h"
#include "GameMode.h"

class GameMode;
enum class PivotMode:Uint8;

{
public://methods
Paddle(GameMode* gameRef, PivotMode inputMode, int x, int y, std::string path);

virtual void Update(float deltaTime);
virtual void Draw(float interpolation);
};

GameMode.h

#pragma once
#include "SDL2\SDL.h"
#include <string>
#include <vector>
#include <memory>
#include "App.h"
#include "Entity.h"

class Entity;

class GameMode
{
friend class App;
private://variables
bool Running;
SDL_Window* Window;
SDL_Renderer* Renderer;
App* AppRef;

public://constructors
GameMode(SDL_Window* Window, SDL_Renderer* Renderer, App* App);
~GameMode();

GameMode(const GameMode&) = delete;
GameMode& operator=(const GameMode&) = delete;
GameMode(GameMode&&) = delete;
GameMode& operator=(GameMode&&) = delete;

public://methods
SDL_Texture* RequestTexture(std::string path)const;
bool IsRunning()const;
SDL_Renderer* GetRenderer()const;

private://methods
void Update(float deltaTime);
void Draw(float interpolation);
};

##### Share on other sites
4 minutes ago, MarcusAseth said:

Paddle Inherit from Entity, and both Paddle and Entity need to #include "GameMode.h" in order to pass down the constructor a GameMode* and store it inside of every Entity.

No they don't. You can forward declare GameMode if all you need is to refer to it by pointer.

Then just include GameMode.h in the CPP files.

##### Share on other sites
7 minutes ago, MarcusAseth said:

Paddle Inherit from Entity, and both Paddle and Entity need to #include "GameMode.h" in order to pass down the constructor a GameMode* and store it inside of every Entity.

No they don't; the forward declaration you have of GameMode is sufficient to declare pointers to GameMode. You only need to include the header if you need anything that requires the full definition of GameMode, which you don't unless you actually try to call a method from it, take its size, et cetera. Generally you can defer the inclusion of GameMode.h to the .cpp in this case.

What you are seeing here is that during the compilation of Entity.cpp, you include Entity.h (which, remember, is basically just pasting the content of Entity.h into Entity.cpp -- the compiler is only compiling the TU resulting from preprocessing Entity.cpp). Entity.h includes SDL stuff which is irrelevant, and then includes GameMode.h. GameMode.h. GameMode.h includes a bunch of crap, and then Entity.h (whcih is skipped due to the pragma) and then Paddle.h. Paddle.h doesn't do anything with the include of Entity.h due to the aforementioned pragma.

Thus the compiler is seeing, from top-to-bottom (with irrelevant stuff removed):

• the content of gamemode.h
• the content of entity.h
• the content of entity.cpp

So the compiler is seeing you define Paddle as a subclass of Entity which hasn't actually been defined yet. You can verify this by having the compiler emit the preprocessed source for Entity.cpp, if you like (although it will be a lot of stuff to wade through).

Since Entity.h doesn't need GameMode.h, remove it. That will break the above chain (although you may have this problem elsewhere and may need to perform a similar analysis and correction elsewhere).

##### Share on other sites

Thanks for the answers guys, that totally fixed it!

Also double thanks for the explanation @jpetrie which clarified things a bit, though even with that I can see that I still can't fully wrap my head around it, so I'll try and search for more explanations(but with images, I always need images to easily understand  )

##### Share on other sites

Make a new text and copy Entity.cpp into it. Then, as long as there is any #include "YourFile.h" left in the text:

• Open YourFile.h.
• If YourFile.h contains #pragma once and you've already seen YourFile.h, stop.
• Otherwise, copy all of YourFile.h.
• Paste it into the text file, replacing the original #include.

You can skip the SDL and C++ library includes for sanity. Once you've done that for every #include of your files, read the resulting source code. This is what the compiler is seeing, and it should be clear why this is an issue then.

##### Share on other sites

Ok, maybe I am getting it, so the problem is not that Entity.h is not included, the problem is that it appears below the content of Paddle.h

Does this means I could have solved the problem above also by forward declaring class Entity; inside of Paddle.h?

Edited by MarcusAseth

##### Share on other sites
26 minutes ago, MarcusAseth said:

Does this means I could have solved the problem above also by forward declaring class Entity; inside of Paddle.h?

Not in this case, because Paddle.h declares Paddle which is a subclass of Entity, and inheriting from some type requires the full definition of that type. A forward-declaration won't suffice.

##### Share on other sites

I see, this will be useful to know for sure in the future

##### Share on other sites

You can avoid passing GameMode* gameRef as a parameter to the entity, and paddle, etc. by using a class that gets the data from its list of entities, and its reference to GameMode, then does whatever you have entity doing with it.

Then you shouldn't have to include GameMode.h at all in Entity.h or Paddle.h or their .cpp files. Also, it doesn't look like you need to include Entity.h or Paddle.h in GameMode.h or even declare the classes, just include them in GameMode.cpp if needed, which you probably shouldn't need to.

If GameMode required a pointer to Entity or Paddle this would create a problem with them having references to each other, using shared_ptr or not handling them properly as they are now with a reference counting system, neither one would be released/deleted when the game closed resulting in a memory leak.

##### Share on other sites
23 minutes ago, Yxjmir said:

You can avoid passing GameMode* gameRef as a parameter to the entity, and paddle, etc. by using a class that gets the data from its list of entities, and its reference to GameMode, then does whatever you have entity doing with it.

I don't understand this x_x

Quote

If GameMode required a pointer to Entity or Paddle this would create a problem with them having references to each other, using shared_ptr or not handling them properly as they are now with a reference counting system, neither one would be released/deleted when the game closed resulting in a memory leak.

and this as well x_x