Vortez

Members
  • Content count

    835
  • Joined

  • Last visited

Community Reputation

2714 Excellent

About Vortez

  • Rank
    Advanced Member

Personal Information

  • Interests
    Programming
  1. Just out of curiosity, why the codes windows aren't showing a vertical bar for dragging when the text is more than x number of lines, for example? Or is there a way to do it? The site changed a lot since 3 years ago.
  2. Need help starting programming android apps

    Thanx, great reply. i'll start looking into that right now .
  3. Yeah but that way leave the node's data uninitialized, and a constructor/destructor allow, for example, a c string allocation/deallocation wich would be risky if T is a pointer (to a c string or whatever) uninitialized. Maybe im shooting for the impossible "etopia", something that just can't happen without a compromise? I know i tend to be a little (lot) perfectionist since a few years, it's like i know to many way to do the same things, and im never sure which one to use... Here's my whole code, just for fun... #pragma once //----------------------------------------------------------------------// #include <Windows.h> #include <stdio.h> //----------------------------------------------------------------------// template <class T> class LinkedList; //----------------------------------------------------------------------------- // Linked list node class //----------------------------------------------------------------------------- template <class T> class LinkedListNode { public: LinkedListNode(){prev = next = NULL;} private: T item; LinkedListNode<T> *prev, *next; public: friend class LinkedList<T>; T& GetItem(){return item;} T* GetItemPtr(){return &item;} void SetItem(T& it){item = it;} void SetItemPtr(T* it){item = *it;} LinkedListNode<T> *Prev(){return prev;} LinkedListNode<T> *Next(){return next;} }; //----------------------------------------------------------------------------- // Linked list class //----------------------------------------------------------------------------- template <class T> class LinkedList { public: LinkedList(); ~LinkedList(); public: typedef LinkedListNode<T> NODE; private: int NodesCount; NODE *head, *tail; private: void Initialize(); bool IndexInRange(int index); bool IndexOutOfBounds(int index); private: bool IsHead(NODE* n); bool IsTail(NODE* n); public: int GetSize(); bool IsEmpty(); NODE* GetNode(int index); NODE* GetFirstNode(); NODE* GetLastNode(); bool NodeExist(NODE* n); int FindNode(NODE* n); T* GetItem(int index); bool SetItem(int index, T& item); int FindItem(T& item); bool ItemExist(T& item); NODE* Push(T& item); NODE* Insert(int index, T& item); bool Delete(int index); bool Pop(); void Clear(); }; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //----------------------------------------------------------------------------- // Constructor... //----------------------------------------------------------------------------- template <class T> LinkedList<T>::LinkedList() { Initialize(); } //----------------------------------------------------------------------------- // Destructor... //----------------------------------------------------------------------------- template <class T> LinkedList<T>::~LinkedList() { Clear(); } //----------------------------------------------------------------------------- // Initialise the list //----------------------------------------------------------------------------- template <class T> void LinkedList<T>::Initialize() { head = NULL; tail = NULL; NodesCount = 0; } //----------------------------------------------------------------------------- // Return true if the index is valid //----------------------------------------------------------------------------- template <class T> bool LinkedList<T>::IndexInRange(int index) { return index >= 0 && index < NodesCount; } //----------------------------------------------------------------------------- // Return true if the index is valid //----------------------------------------------------------------------------- template <class T> bool LinkedList<T>::IndexOutOfBounds(int index) { return index < 0 || index > NodesCount; } //----------------------------------------------------------------------------- // Return true if the list is empty //----------------------------------------------------------------------------- template <class T> bool LinkedList<T>::IsEmpty() { return NodesCount == 0; } //----------------------------------------------------------------------------- // Return the number of nodes in the list //----------------------------------------------------------------------------- template <class T> int LinkedList<T>::GetSize() { return NodesCount; } //----------------------------------------------------------------------------- // Return true if the given pointer is the head node //----------------------------------------------------------------------------- template <class T> bool LinkedList<T>::IsHead(NODE* n) { return head == n; } //----------------------------------------------------------------------------- // Return true if the given pointer is the tail node //----------------------------------------------------------------------------- template <class T> bool LinkedList<T>::IsTail(NODE* n) { return tail == n; } //----------------------------------------------------------------------------- // Return the node at the given position //----------------------------------------------------------------------------- template <class T> LinkedListNode<T>* LinkedList<T>::GetNode(int index) { int i = 0; NODE* node = head; while(node){ if(index == i) return node; node = node->Next(); i++; } return NULL; } //----------------------------------------------------------------------------- // Return the first node of the list //----------------------------------------------------------------------------- template <class T> LinkedListNode<T>* LinkedList<T>::GetFirstNode() { return head; } //----------------------------------------------------------------------------- // Return the last node of the list //----------------------------------------------------------------------------- template <class T> LinkedListNode<T>* LinkedList<T>::GetLastNode() { return tail; } //----------------------------------------------------------------------------- // Return true if the given node can be found in the list //----------------------------------------------------------------------------- template <class T> bool LinkedList<T>::NodeExist(NODE* n) { NODE* node = head; while(node){ if(node == n) return true; node = node->Next(); } return false; } //----------------------------------------------------------------------------- // //----------------------------------------------------------------------------- template <class T> int LinkedList<T>::FindNode(NODE* n) { int i = 0; NODE* node = head; while(node){ if(node == n) return i; node = node->Next(); i++; } return -1; } //----------------------------------------------------------------------------- // Return the node at given position //----------------------------------------------------------------------------- template <class T> T* LinkedList<T>::GetItem(int index) { if(IndexInRange(index)){ NODE* node = GetNode(index); if(node) return node->GetItemPtr(); } return NULL; } //----------------------------------------------------------------------------- // //----------------------------------------------------------------------------- template <class T> bool LinkedList<T>::SetItem(int index, T& item) { if(IndexInRange(index)){ NODE* node = GetNode(index); if(node){ node->SetItem(item); return true; } } return false; } //----------------------------------------------------------------------------- // new //----------------------------------------------------------------------------- template <class T> int LinkedList<T>::FindItem(T& item) { int i = 0; NODE* node = head; while(node){ if(node->GetItem() == item) return i; node = node->Next(); i++; } return -1; } //----------------------------------------------------------------------------- // //----------------------------------------------------------------------------- template <class T> bool LinkedList<T>::ItemExist(T& item) { return FindItem(item) >= 0; } //----------------------------------------------------------------------------- // //----------------------------------------------------------------------------- template <class T> LinkedListNode<T>* LinkedList<T>::Push(T& item) { NODE* new_node = new NODE; NodesCount++; // No head? if(!head){ head = new_node; tail = new_node; } else { // Update previous and next pointers new_node->prev = tail; tail->next = new_node; // Update the tail tail = new_node; } // Copy the node's data new_node->SetItem(item); return new_node; } //----------------------------------------------------------------------------- // //----------------------------------------------------------------------------- template <class T> LinkedListNode<T>* LinkedList<T>::Insert(int index, T& item) { if(IndexOutOfBounds(index)) return NULL; // Get a pointer to the node where we want to insert, if any NODE* node = GetNode(index); if(!node) return Push(item); // Allocate the new node NODE* new_node = new NODE; NodesCount++; // Update new node pointers new_node->next = node; new_node->prev = node ? node->prev : NULL; // Create next and previous node pointer NODE* prev_node = new_node->prev; NODE* next_node = new_node->next; // Update next and previous node pointer if(prev_node){prev_node->next = new_node;} if(next_node){next_node->prev = new_node;} // Update head and tail pointers if(!new_node->prev){head = new_node;} if(!new_node->next){tail = new_node;} // Copy the node's data new_node->SetItem(item); // Return the newly allocated node return new_node; } //----------------------------------------------------------------------------- // //----------------------------------------------------------------------------- template <class T> bool LinkedList<T>::Delete(int index) { // Check for index out of bounds exception... if(!IndexInRange(index) || IndexOutOfBounds(index)) return false; // Get prev and next nodes pointers NODE* node = GetNode(index); NODE* prev = node->Prev(); NODE* next = node->Next(); // Update prev and next nodes pointers if(prev){node->prev->next = next;} if(next){node->next->prev = prev;} // Update head and tail pointers if(IsHead(node)){head = node->next;} if(IsTail(node)){tail = node->prev;} // Delete the node delete node; NodesCount--; return true; } //----------------------------------------------------------------------------- // Remove the last node of the list //----------------------------------------------------------------------------- template <class T> bool LinkedList<T>::Pop() { return Delete(NodesCount - 1); } //----------------------------------------------------------------------------- // Clear the entire list //----------------------------------------------------------------------------- template <class T> void LinkedList<T>::Clear() { while(Pop()); } Feel free to critic.
  4. yea that's my problem, how do i cope with this? I mean, i cannot in advance since T could be anything... That's a good point.
  5. Why not use a high-precision timer? You can look at mine (Timer.h, Timer.cpp) for example . I always used this kind of timer when coding a game and it always gave me great result in the past. Honestly, what's the point of fixed timestep except in some circumstance, and hard coded frames per seconds limits if you can just use vsync to do the job for you? Just my 2 cents here...
  6. I guys, i have some questions regarding the design of my node class for a linked list or stack or whatever... Let's show me some code, then i'll explain: //----------------------------------------------------------------------------- // Linked list node class //----------------------------------------------------------------------------- template <class T> class LinkedListNode { public: LinkedListNode(){prev = next = NULL;} private: T item; LinkedListNode<T> *prev, *next; public: T GetItem(){return item;} void SetItem(T it){item = it;} LinkedListNode<T> *Prev(){return prev;} LinkedListNode<T> *Next(){return next;} }; That method is fine, but waste time in GetItem()/SetItem(), so, i could add those 2 methods, ie: T* GetItemPtr(){return &item;} void SetItemPtr(T *it){item = *it;} But that's ugly, and even if i use only one set of GetItem()/SetItem(): ie replace previous code with: T* GetItem(){return &item;} void SetItem(T *it){item = *it;} or T& GetItem(){return item;} void SetItem(T &it){item = it;} it seem each methods has his pros and cons. What's worst is that you can't use more than one set or the compiler will cry... Also, if the object T is not a class, but a simple variable (an int for example), it dosen't have a constructor, and im not sure if: ZeroMemory(&item, sizeof(item)); will work on any kind of data (especially classes). Any advice?
  7. Hi guys, long time no see! (I was pretty active a few years ago on this forum ). Anyway, long story short, I want to make apps for my android phone, but after following some tutorials and ending up cloging my hard drive for nothing, i can't seem to be able to put all the pieces together concerning all the crap to install, since there's always something that changed since when the tutorial was wrote, or stuffs like that. Im usually not a noob to this kind of things but it seem there's always something going wrong when i try (it's like the modules im installing in eclipse just never end, im always missing something, argggg!) Let's say i start a fresh copy of Win7 in VMWare, can somebody tell me the EXACT steps to perform, in order, so that i can compile an app without problem, i know im asking a lot, but i believe that's a fair thing to ask, since it might help others peoples that land to this post too. I would really like a recipe kind of answer, lol. Also, i know this sound dumb, but anyway, i have no idea how the compilation work, wich file or files get created as output, and, the most important, how the heck do i load this thing in the cellphone, do i HAVE to use google store, or is it optional? Im used as a win32 programmer, i know almost nothing yet of android platform ) . Im not in a hurry for an answer, so take all the time you need to give a detailled explanation please (otherwise im back to square one!) Thx in advance for your time.
  8. Hi, i just wanted to know if it's possible to compute a hash on the gpu, like crc32 or something stronger(sha-1?) , in an efficient manner? If so, how, how would i retreive the result?
  9. Hi guys, i've been toying with the "game of life" for a few days, and been able to achieve blazing speed by using shaders to compute the next generation on the gpu (it can also do all the work on the cpu, so i can compare both methods speed). The problem i have is this: at some point, the game will be "stuck", generating the same 2 frames over and over, alternating between them forever... I need a way to detect this. If i do it on the cpu, it's easy since i could just compare the last few frames to see if the game is stuck, using memcmp, or even better, generate a hash while computing the next gen and just compare the last few of them. Easy. But when i use the gpu path, i only have the first frame in client memory (ram), and i don't know how to solve this problem other than use the slow glReadPixel. Perhaps a PBO could help, but im not very familliar with them. From what i remember, it wouldn't be that much faster anyway. What i want is some clever way to do that without losing too much framerate. So, any though? ///////////////////////////////////////////////////////////////////////// Those 2 files simply show how i use the code for both mode: CPU example code.txt GPU example code.txt Those are the 2 main classes of the project: GLEngine.h GLEngine.cpp The game of life.h The game of life.cpp Note:  (most relevant bits of code is near the bottom of each files) And finally, the shaders: Life.vs + Life.fs If you see anything i can improve on, please let me know!
  10. Proper C++ header file?

    I would also suggest to replace   #ifndef INCLUDED_TILEMAP_H #define INCLUDED_TILEMAP_H   by   #pragma once   it's simpler and you don't need the #endif at the end :)
  11. creating a fullscreen game in Delphi

    Since most win32 api calls can be used in delphi, you could check my code and experiment with it. You dont need the whole thing, just check whhat i do in the fullscreen part.   Vortez.
  12. Delphi Programming: Dead or Alive?

    I love programming win32 apps with c++ builder and delphi, i still do today, too bad the price is so high or otherwise it could kick the ass of msvs, in the form  and components design at least. It's so easy to create custom components in delphi it's almost a joke. Too bad too many ppls jumped on the c# wagon. :(
  13. In addition to openal there's also the FMOD library, it's relatively easy to use too.
  14. Ok thx, i'll try that when im home.
  15. Bad values from DLL functions

    One thing you need to be carefull when using dlls is the calling convention, that got me a few times, especially if the dll and the code using it arent made by the same compiler or language. Having said that, it's hard to say without seeing any code.