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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Eyfenna

Pages: [1]
1
SFML development / Re: How should SFML handle non-legacy shaders?
« on: July 08, 2019, 11:00:21 pm »
I'm currently learning a bit of opengl 4 and basicly was thinking about how to handel the topic of shaders in an api like sfml - as in this version of opengl a vertex and a fragment shader are mandatory for anything to be rendered - and wondered if maybe a SetShaders function for drawables and providing a basic shader libary would be a good idea.
Anyway as soon as I'm further into glsl I'm willing to assist and opengl I might be willing to assist.

2
General / Re: Hexagon grid
« on: May 27, 2019, 09:22:27 pm »
The post lead to me doing thinking about the code.

9) The formulas for setting hexagon vertices look scary. Pretty sure it can be simplified and don't be full of copy-pasted

Good tip, I concluded that a

const sf::Vector2f Orientation[] = { {-.5f,-0.25f},{0.f,-0.5f}, {0.5f,-0.25f},{0.5f,0.25f},{0.f,0.5f},{-0.5,0.25f}, };
(imitating a thing from redblobgames)

allows to shorten the vertix location setting code for an empty hexagon(sf::LineStrip) to

int a;
for (int i = 0; i < 7; ++i)
{
if (i - 6 >= 0) a = i - 6;
else a = i;
mBare.push_back(sf::Vertex(sf::Vector2f((mPosition.x + width*Orientation[a].x), (mPosition.y +height*Orientation[a].y))));
}
 

similar for the textured vertices location.


7) I'd store all callbacks as std::function's, not as pointers to functions - it provides a lot more flexibilty.

Done, std::bind is sort of easiert to handle than pointers to memberfunction once one has understood it. The reason I used function pointers was that callback with them came to my mind at first and std::bind doesn't appear in tutorial pages about callbacks I found on google.

With std::function<> callback I found also that I can leave out the pointer to the class. That is nice, works with the maploader.


3
General / Re: Hexagon grid
« on: May 20, 2019, 08:18:10 pm »
Thanks for the helpfull replies ;D

As I'm not so sure with Vertexarrays I went following way:
For the hexagonal grid I made a hexagon class(drawable) which holds the vertexarray to be more precise std::vector<vertex>. A templated GameGrid class holds a std::vector of Hexagons for example and generates the field.
I did some refractoring on it and except a pointer to a maploader - that holds the map information in an array - and three member function pointers on this class for the getters in this way I could remove the maploader header from the  GameGrid header.
I was wondering if that is still good c++ or overengineering things?

Well before describing it lengthily I post the source code for GameGrid and the hexagon class
The code for GameGrid template is all in a header now, moving things to an .inl when I played around with this format.
In so far the code for GameGrid is lengthy:

(click to show/hide)


Here the code for the Hexagon class:

the header
(click to show/hide)

and here the .cpp with the bodies of the memberfunction for Hexagon:

I left out the dependecy for VisualStudio
(click to show/hide)

4
General / Re: Hexagon grid
« on: May 13, 2019, 02:09:50 am »
The error message is (about translated) [same for std::map<sf::Vector2i, sf::Vector2i>]

Error C2664   "bool Hexgrid::GetGridPlace::<lambda_5b26f5554823591ff0c2ae8c47a36fad>::operator ()(std::pair<sf::Vector2i,sf::Vector2i> &) const" : Conversion from argument 1  "std::pair<const _Kty,_Ty>" to "std::pair<sf::Vector2i,sf::Vector2i> &" not possible. ConsoleApplication87   c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\algorithm   174   

Thanks for the hint with the floating point numbers.

Solved it one possible way:

I went a different way and safe the grid position (offset coordinates according to redblob site) inside the Hexagon and do an inRange comparison with the central point:

(click to show/hide)

and use this in a function inside the Hexgrid class:

(click to show/hide)

5
General / Hexagon grid
« on: May 12, 2019, 02:58:18 pm »
Hello,  I got a hexagonal grid, and it does display right and I can even put textures on each hexagon. My problem is following:

In an additional std::map I store the coordinates of the central point and the x-y coordinate of the hexagon in the grid in a std::map<sf::Vector2f, sf::Vector2i> now I try to get the sf::Vector2i as return of a map search for displaying the Hexgrid coordinates in console for the one mouse if hoovering over in the window.  I'm trying to do this with find_if algorithm on the map. The function is part of the Hexgrid class which holds the hexagonal grid:

(click to show/hide)

however compiler notifies me of an error on converting pairs.

I also tried with another lambda:

(click to show/hide)

Here the compiler can't convert pair to sf::vector2f.


So after a search I found that I might have to write something extra but can't realy bend my head around what it is and why this specific thing is lacking. Thanks for a response or a hint.

6
I'm playing arround with particle effects and while I'm not managed to code the finder function to connect emitter nodes to particle nodes I managed to code some affectors as lambda functions, in case somebody wondered about how this can be done.
I'm on the other hand am interested in how can the finder command be done?

Simple fall from up to down:
Code: [Select]
function<void(Particle&, Time)> Fallaffector = [&](Particle& particle, Time dt) { particle.position += Vector2f(0.f,50.f)*dt.asSeconds();};
Can look comparable to a waterfall cascade in case start position of particle is randomized as (start position + std::rand()%factor):
Code: [Select]
function<void(Particle&, Time)> Fallaffector = [&](Particle& particle, Time dt) {float posx = (particle.position.x - 400.f) / 2; if (particle.position.y < 350) { particle.position += Vector2f(-posx / 15 + static_cast<int>(particle.position.x) % 30, std::rand() % 50 + std::rand() % 75)*dt.asSeconds(); } else { particle.position += Vector2f(std::rand()%140, std::rand()%50)*dt.asSeconds(); }};
Circular rotation around 300 300:
Code: [Select]
function<void(Particle&, Time)> Rotator = [&](Particle& particle, Time dt) {Vector2f pos = particle.position; float s = sin(55); float c = cos(55); pos -= Vector2f(300 , 300); float xnew = pos.x*c - pos.y*s; float ynew = pos.x * s + pos.y * c; xnew += 300; ynew += 300; particle.position = Vector2f(xnew, ynew); };
Lines become a rotating cloud
Code: [Select]
function<void(Particle&, Time)> Rotator = [&](Particle& particle, Time dt) {Vector2f pos = particle.position; float s = sin(55); float c = cos(55); pos -= Vector2f(300 + std::rand()%10, 300); float xnew = pos.x*c - pos.y*s; float ynew = pos.x * s + pos.y * c; xnew += 400; ynew += 300; particle.position = Vector2f(xnew, ynew); };

7
General discussions / Re: Creating a new sf::Event object in each loop?
« on: September 30, 2017, 07:36:27 pm »
Did wonder about this myself.
personally I tend to declare sf::Event before the main loop.

8
Scene Graphs are quite a generic topic. If you find something for another implementation, you'll most likely be able to apply the idea to your own scene graph.

What kind of information are you looking for?

https://en.wikipedia.org/wiki/Scene_graph

basically different node types, the book provides source code for a generall do it all node while other sources in the internet disringuish between group and renderable nodes.

open scene graph, I think, knows a structure like switch node.

secondly even when command is a good pattern to influence leafs it fells a bit clumsy in so far as I have to modify the source code of the leaves for a command to work and was wondering if there are other patterns that can be used in the same way?

9
SFML Game Development
https://www.packtpub.com/game-development/sfml-game-development


this might be offtopic, yet I aquired this book myself and am fascinated by the topic of scene graphs. i did some google research on this  topic yet found only sites that explain the uses of existing programs relying on scene graph (i.e. open scene graph and similars)

I was wondering if there is someone who knows more about scene graphs or if theres further lecture on it?

10
so far what does not run is the register state template that captures this in the lambda. even enabling shared from this and creating a shared ptr inside the class with self and vapturing self by ref gets me a bad weak ptr error.
since the States stored in the StateContainer and StateFactory are not shared among other entities, i recommend using std::unique_ptr<> instead of std::shared_ptr.
using StateContainer = std::vector<std::pair<StateType, std::unique_ptr<State>>>;
using StateFactory = std::unordered_map<StateType, std::function<std::unique_ptr<State>()>>;
...
template<class T>
void StateManager::registerState(StateType stateType){
        mFactory[stateType] = [this]()->std::unique_ptr<State>{
                return std::make_unique<T>(this);
        };
}

thanks that helped and header include juggling, it does work properly now.

11
so far what does not run is the register state template that captures this in the lambda. even enabling shared from this and creating a shared ptr inside the class with self and vapturing self by ref gets me a bad weak ptr error.
the other thing is the utility get working directory macro the char array is not accepted by the winapi function in vs 2015.

12
its my second sfml book and have to say thanks for the many stimula though i started to rebuild the examples with smart pointers i'm able to get nearly everything  to run.

Pages: [1]