Ich kann leider fast nur Java programmieren, deshalb habe ich folgendes Problem:
Beim SLI-Harmonizer, der die berechneten Bilder pro Sekunde der Grafikkarten in einem System beschränken soll, besteht das Problem, dass die Zahlen für die Intervalle (in ms, "1000/xx") immer ganzzahlig betrachet werden (in Java wärs zB. "double").
Dies führt dann in der Ausführung zu Ungenauigkeiten, zB. 50 statt 48 frames/s, was an sich nicht sonderlich schlimm ist, allerdings wenn man z.B. eine Framerate wählen will, die mit der Frequenz des Monitors Hand in Hand geht, führt dies zu Problemen.
Deshalb möchte ich die Intervall-Timings als FloatingPoint-Zahlen definieren und verwenden.
Es ist wohl nicht sehr kompliziert, doch ich kann es einfach nicht...:löl:
Ausserdem stellt sich die Frage, ob dies (spürbar) mehr Leistung vom System abverlangt.:confused:
Der Code:
C-Quellcode
- [COLOR='darkgreen']// timer.cpp : Defines the entry point for the DLL application.
- //[/COLOR]
- #include "stdafx.h"
- #include "timer.h"
- #ifdef _MANAGED
- #pragma managed(push, off)
- #endif
- [COLOR='darkgreen']// simple timer class[/COLOR]
- #pragma pack(push, 8)
- class SimpleTimer{
- private:
- __int64 m_frequency;
- __int64 m_baseTime;
- __int64 t;
- __int64 lastTime;
- __int64 thisTime;
- __int64 newTime;
- public:
- __int64 elapsed()
- {
- newTime=0;
- QueryPerformanceCounter(reinterpret_cast<LARGE_INTEGER*>(&newTime));
- t = (newTime - m_baseTime)/m_frequency;
- m_baseTime=newTime;
- return t;
- }
- SimpleTimer()
- {
- init();
- }
- ~SimpleTimer()
- {
- }
- void init()
- {
- m_frequency=m_baseTime=thisTime=lastTime=0;
- QueryPerformanceFrequency(reinterpret_cast<LARGE_INTEGER*>(&m_frequency));
- QueryPerformanceCounter(reinterpret_cast<LARGE_INTEGER*>(&m_baseTime));
- m_frequency/=1000;
- }
- };
- #pragma pack(pop)
- SimpleTimer *myTimer=NULL;
- BOOL APIENTRY DllMain( HMODULE hModule,
- DWORD ul_reason_for_call,
- LPVOID lpReserved
- )
- {
- switch (ul_reason_for_call)
- {
- case DLL_PROCESS_ATTACH:
- if(!myTimer)
- myTimer=new SimpleTimer();
- break;
- case DLL_THREAD_ATTACH:
- break;
- case DLL_THREAD_DETACH:
- break;
- case DLL_PROCESS_DETACH:
- if(myTimer)
- delete myTimer;
- myTimer=NULL;
- break;
- }
- return TRUE;
- }
- #ifdef _MANAGED
- #pragma managed(pop)
- #endif
- const int framesToConsider=2;
- extern "C"{
- __declspec(dllexport) void waitFunction()
- {
- if(!myTimer)
- return;
- [COLOR='DarkGreen']/*
- * Monitoring der letzten 2/3/4 frames (SLI/T-SLI/Q-SLI)
- * Bestimmung der durchschnittlichen frametime
- * Verzögerung der Ausgabe in Abhängigkeit vom Durchschnitt für die nächsten 2/3/4 frames
- */[/COLOR]
- static int callCounter=0;
- static long timeToWait=0;
- static long lastFramesTime[16]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
- static long lastFramesTotalTime=0;
- static char tmp[1024];
- lastFramesTime[callCounter]=myTimer->elapsed();
- [COLOR='darkgreen']//sprintf(tmp, "\ntotal %d frame(%d) time %d", (1000/30), callCounter, lastFramesTime[callCounter]);
- //OutputDebugStringA(tmp);
- // limit to 30 fps[/COLOR]
- if(lastFramesTime[callCounter]<([COLOR='Red']1000/30[/COLOR]))
- {
- timeToWait=([COLOR='red']1000/30[/COLOR])-lastFramesTime[callCounter];
- Sleep(timeToWait);
- myTimer->elapsed(); // reset timer, otherwise the next frame will be too long
- }
- }
- }
Vielen Dank schonmal an alle für die Hilfe!
mfg didic
iouRzer9"iuz74g8974t89?oz&4it0zh9(/H3gf7 ...