Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411500 Posts in 69373 Topics- by 58428 Members - Latest Member: shelton786

April 25, 2024, 11:43:02 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)General thread for quick questions
Pages: 1 ... 58 59 [60] 61 62 ... 69
Print
Author Topic: General thread for quick questions  (Read 135374 times)
ferreiradaselva
Level 3
***



View Profile
« Reply #1180 on: December 07, 2017, 11:36:48 AM »

You can only have one source of floating point incrementation. All other copies need to be set or offset from the source repeatedly. This establishes consistency.

^ (int32_t day, int32_t hour, int32_t minute, float seconds)

The same principle is applied to object position (but people insist that using double will solve their problem). If your map is too big, use chunks (with an associated int32_t cell_x, int32_t cell_y), then the object position is just an float-point offset to the current chunk they are in.
Logged

Crimsontide
Level 5
*****


View Profile
« Reply #1181 on: December 07, 2017, 12:13:01 PM »

I've always just used uint64_t (or something similar) for things like position and time.  Its simplifies everything so much.  I even have a few simple fixed point math routines to be used (sparingly) in vertex shaders.
Logged
ferreiradaselva
Level 3
***



View Profile
« Reply #1182 on: December 07, 2017, 01:43:18 PM »

Coincidently, I was just looking at some fixed-point math libraries on github.
Logged

Crimsontide
Level 5
*****


View Profile
« Reply #1183 on: December 07, 2017, 02:28:34 PM »

Coincidently, I was just looking at some fixed-point math libraries on github.

Addition, negation, and multiplication will be all you need 99% of the time, are pretty trivial to implement, and are fast enough for most things.  If you need trig, hyperbolic, or any higher functions then use floating point.
Logged
Garthy
Level 9
****


Quack, verily


View Profile WWW
« Reply #1184 on: December 07, 2017, 02:43:37 PM »


Two clock don't solve the problem since

You use a single time source and generate <n> virtual clocks. Something like:

Code:

float lastTime = 0.0f;
float gameClock = 0.0f;
float guiClock = 0.0f;

void UpdateClocks()
{
  float currentTime = GetCurrentRealTime();
  float delta = currentTime - lastTime;
  lastTime = currentTime;

  if (!paused)
    gameClock += delta;
  guiClock += delta;

  // scaledClock += delta * speedup;
  // logClock += delta;
  // resettableClock += delta;
  // if (resettableClockTrigger)
  //   resettableClock = 0.0f;
}

I promise it works. You've just seen two people who used it in games swap notes in the posts here.

Crimsontide's suggestion (uint64_t) is useful if you run into floating-point precision issues.

Logged
Schrompf
Level 9
****

C++ professional, game dev sparetime


View Profile WWW
« Reply #1185 on: December 08, 2017, 12:54:49 AM »

Well... don't use floats then. Nowadays I suggest to simply use std::chrono::high_resolution_timer, which already does the right thing. Use it to query the current time, use it once to query the number of ticks per second. Then create a small class which simply does query the elapsed ticks once per frame and accumulate those (scaled and paused optionally) in an int64_t. Convert to/from floating point only for display purposes, or employ the chrono units system.

And note that I wrote int64_t, not uint64_t. I don't remember exactly why I did this, but I think I needed to initialize some time stamps with negative values here and there. That's a nice trick for "what's the last time that this and that happened" values, but you sure can solve this with uint64_t, too.

The high resolution counter has a resolution of a few billion ticks on Intel CPUs and a few million ticks on AMD CPUs. So using (u)int64_t allows you to run for a few billion seconds before it overflows, which is definitely enough for any purpose.
Logged

Snake World, multiplayer worm eats stuff and grows DevLog
gimymblert
Level 10
*****


The archivest master, leader of all documents


View Profile
« Reply #1186 on: December 08, 2017, 06:28:56 AM »

Yeah I think I'm stressing out because float is giving me nightmare ... They has cause me pain in the past.

Though I'll use unity engine in the end.
Logged

qMopey
Level 6
*


View Profile WWW
« Reply #1187 on: December 08, 2017, 11:41:51 AM »

Typically 64bit ints are used for high resolution timers. A floating point timer is an approximation if underlying integer based timers anyway. There shouldn’t be desync problems if int based timers are used.
Logged
gimymblert
Level 10
*****


The archivest master, leader of all documents


View Profile
« Reply #1188 on: December 08, 2017, 06:32:03 PM »

The desync happen because I did something like:
if time accumulation > order of magnitude
- increase order of magnitude
- set time accumulation to 0

I should add something like:
time accumulation = time accumulation - order of magnitude

Then I won't lose small amount of time that drift over time.

I'm currently more concern about what gameplay implication a fix dt after a pause can have, I have so many pause/unpause exploit, ninja gaiden (xbox og) queue button press and only execute the pause after some action are taken, other game have a kind of multiple frame cooldown between pause events, but it's probably YAGNI overthinking. I'm making a rpg, not exactly fast pace action.

Anyway designing time counters is a bit more involving that I initially thought lol.
Logged

ferreiradaselva
Level 3
***



View Profile
« Reply #1189 on: December 08, 2017, 06:59:07 PM »

What are you using (game engine, framework)?
If it's something that you have control of the main loop, pause/resume should be actually be pretty easy.
Logged

GainDeveloper
Level 0
**


View Profile
« Reply #1190 on: December 21, 2017, 05:49:52 PM »

Does anyone have any experience with data inheritance in Unity (Or CSharp) ?
That is to have two objects of the same type where one can inherit all variables from the other and override them at wish.

I have had no luck finding a single article or post asking about how to approach such functionality which makes me think I am using the wrong term?
Just looking for something to start from Smiley
Logged
InfiniteStateMachine
Level 10
*****



View Profile
« Reply #1191 on: December 21, 2017, 06:25:02 PM »

Does anyone have any experience with data inheritance in Unity (Or CSharp) ?
That is to have two objects of the same type where one can inherit all variables from the other and override them at wish.

I have had no luck finding a single article or post asking about how to approach such functionality which makes me think I am using the wrong term?
Just looking for something to start from Smiley

Do you mean class inheritance?

If so it's quite easy. In your base class, mark the methods you want to be override-able as "virtual" and then in any child class use the override keyword to change their behavior.

In regards to member data. You can make Properties virtual IIRC but I've rarely done it since you are really modifying the way the data is acquired which really means you are overriding an accessory method.

Does that answer your question? I may have misunderstood your question.

Logged

GainDeveloper
Level 0
**


View Profile
« Reply #1192 on: December 22, 2017, 12:51:41 AM »

Do you mean class inheritance?

I don't (Which makes me think I'm using the wrong term).
What I'm looking for is inheritance of serialised data, so for example if I have Class1 that has the variables "Name" and "Health". I have objects A & B both of Class1. ObjectA sets it's name and health respectively and 'inherits' from nothing. ObjectB however inherits from ObjectA, so both the name and health are inherited meaning changes to health in ObjectA would also change health in ObjectB.
Hope I'm explaining it well enough Smiley
Logged
JWki
Level 4
****


View Profile
« Reply #1193 on: December 22, 2017, 03:11:39 AM »

Do you mean class inheritance?

I don't (Which makes me think I'm using the wrong term).
What I'm looking for is inheritance of serialised data, so for example if I have Class1 that has the variables "Name" and "Health". I have objects A & B both of Class1. ObjectA sets it's name and health respectively and 'inherits' from nothing. ObjectB however inherits from ObjectA, so both the name and health are inherited meaning changes to health in ObjectA would also change health in ObjectB.
Hope I'm explaining it well enough Smiley

That's usually called "prototypes", "blueprints" or "prefabs" or something similiar.
In Unity that's roughly what prefabs do.
Logged
GainDeveloper
Level 0
**


View Profile
« Reply #1194 on: December 22, 2017, 04:34:06 AM »

That's usually called "prototypes", "blueprints" or "prefabs" or something similiar.
In Unity that's roughly what prefabs do.

Thanks! I'll try searching more with those terms Smiley
Prefabs are great but without support multiple layers of hierarchy/ inheritance it's not really suitable
Logged
Ordnas
Level 10
*****



View Profile WWW
« Reply #1195 on: December 24, 2017, 08:01:41 AM »

Do you mean class inheritance?

I don't (Which makes me think I'm using the wrong term).
What I'm looking for is inheritance of serialised data, so for example if I have Class1 that has the variables "Name" and "Health". I have objects A & B both of Class1. ObjectA sets it's name and health respectively and 'inherits' from nothing. ObjectB however inherits from ObjectA, so both the name and health are inherited meaning changes to health in ObjectA would also change health in ObjectB.
Hope I'm explaining it well enough Smiley

It I understood correctly, in your example you said that A and B are of class Class1. So B can't inherits from A, inheritance is when Class1 has a child class.

If you want B to set the same value of A, that it is a copy constructor. Or you can create a function that get A and creates B with values from A.
Logged

Games:

InfiniteStateMachine
Level 10
*****



View Profile
« Reply #1196 on: December 27, 2017, 06:02:04 PM »

I think I understand now.

It makes me kind of think of Lua where you setup some base table and then copy it and then modify/add stuff on the copy but it doesn't really have any link to the source it was copied from.

I guess the term for that is prototyping like jwki mentioned? Is that correct?
Logged

Ordnas
Level 10
*****



View Profile WWW
« Reply #1197 on: December 28, 2017, 01:00:01 AM »

Mmm I don't know. I used Lua for a project, but now I can't remember a lot of things very well. I think that GainDeveloper just wanted the easier thing, because he mentioned Unity, but in case the prototype pattern is something that do that thing:

http://gameprogrammingpatterns.com/prototype.html
Logged

Games:

oahda
Level 10
*****



View Profile
« Reply #1198 on: December 29, 2017, 08:07:37 AM »

My head is a little mushy today and I don't have enough code in place to properly test it, plus I'm not really sure which is left or right or up or down in GL when it comes to rotations and such… If I have a transform matrix for a camera, same as the transform matrix of any object in the world, is the inverse of that matrix the correct view matrix for the vertex shader? At least at a glance it seems to be working correctly.
Logged

JWki
Level 4
****


View Profile
« Reply #1199 on: December 29, 2017, 09:52:05 AM »

My head is a little mushy today and I don't have enough code in place to properly test it, plus I'm not really sure which is left or right or up or down in GL when it comes to rotations and such… If I have a transform matrix for a camera, same as the transform matrix of any object in the world, is the inverse of that matrix the correct view matrix for the vertex shader? At least at a glance it seems to be working correctly.

Yes. Think about what that transformation does. Basically you move and rotate the world around the camera.
Logged
Pages: 1 ... 58 59 [60] 61 62 ... 69
Print
Jump to:  

Theme orange-lt created by panic