• Advertisement


  • Content count

  • Joined

  • Last visited

Community Reputation

464 Neutral

1 Follower

About Falken42

  • Rank

Personal Information


  • Twitter
  • Github
  • Twitch
  • Steam

Recent Profile Visitors

2533 profile views
  1. Crystal Clash

    Album for Crystal Clash
  2. Crystal Clash

    Crystal Clash competitively pits you against other online players around the world in realtime, requiring quick puzzle solving skills and fast reactions in order to win. In the world of Crystal Clash, you are the lord of your castle, and your soldiers, called "Bits", assist you in expanding your territory. Both you and your opponent simultaneously solve the same set of pixel logic puzzles, and with each correct fill, your Bits automatically advance and attack your opponent. Decide the best strategy for your Bits by controlling the lanes they attack on -- either keeping your defense strong, or pushing them all for a full attack to claim your opponent's area. For each puzzle you solve, you'll gain experience to level up your Bits, increasing their strength, defense, speed and hit points, and will unlock new and powerful skills for use in battle! Crystal Clash is continually being updated with additional features, with a new release approximately every two to three weeks. If there is something you would like to see in the game, or if you have any comments or suggestions for us, we'd love to hear from you! Please feel free to contact us anytime at: support@coldfusion.co.jp or leave us an in-game review! Crystal Clash is Cold Fusion’s first independent and original game, built upon its newly developed multithreaded, high performance cross-platform rendering and multiplayer networking technology. For more information about our engine tech, please visit our website at: https://coldfusion.co.jp
  3. [C++] class hierarchy design

    First of all, thanks everyone for your comments and suggestions. Quote:Original post by Antheus Main reason why it doesn't fit well with C++ is the static compilation model. This type of design almost requires introspective and run-time code modification capabilities. In C++ these are typically done at compile-time using special pre-processing and code generation. This is the real answer I was looking for, actually -- sadly, it's just not something easily done with C++. I did some reasearch on Aspect Oriented Programming, and found FeatureC++, which looks like it would do what I'm trying to accomplish. I'll have to play with it. An implementation of the Decorator pattern seems like it would be possible too, but object creation would certainly look ugly. Quote:Original post by theOcelot Optionally support both in the base class? This seems like a bad use for inheritance, precisely because of the problem you're having. My intent is to design an interface that allows the user to think out of the box. The user might want to do something completely different -- like say, pass the OpenGL commands through a network socket. Ideally, the user should still be able to use my provided cached implementation, and still be able to extend the functionality as he/she desires. I can't just limit them to a template with or without logging, for example.
  4. Coding Horror posted a great article about this exact subject. Dedicating a PC to the task of routing would certainly do the task, but it's also extremely overboard. If you don't mind the power bill/space used/noise emitted/etc., then by all means. :)
  5. Ah, this wonderful bug. I don't think there is any real solution, but there is a workaround: 1) Add a: void doAbsolutelyNothing() { } function in the same source file as the instances of the objects you are creating. If you have multiple source files with instances, you'll need multiple functions with different names. 2) Call this: doAbsolutelyNothing(); function from some other part of your source, such as in initialization code, or code which is only called once. The VC linker doesn't include object files in the final .exe with no external references as it assumes they're never used (it's apparently not smart enough to notice that object variables are simply instanced in that compilation unit). By adding an external reference, you force the inclusion of that object in the linker. You could optionally make a variable reference to your TestInstance from some other part of your source which would work just as well, but since you're generating these names with macros, that seems like it would be much more difficult for you.
  6. Hello all, I've been doing some code redesign lately, and have come across a design issue I can't seem to answer easily myself. Suppose I have a simple OpenGL wrapper class, for example: class OpenGL : public GraphicsDriver { public: ... virtual void depthMask(GLboolean flag) { glDepthMask(flag); } virtual void begin(GLenum mode) { glBegin(mode); } virtual void end() { glEnd(); } ... }; Then I have a derived class supporting logging: class OpenGLLogger : public OpenGL { public: ... virtual void depthMask(GLboolean flag) { printf("glDepthMask(%d)\n", flag); OpenGL::depthMask(flag); } virtual void begin(GLenum mode) { printf("glBegin(%d)\n", mode); OpenGL::begin(mode); } virtual void end() { printf("glEnd()\n"); OpenGL::end(); } ... }; And I also have another derived class supporting state caching (this is obviously a very simple example): class OpenGLCaching : public OpenGL { public: ... virtual void depthMask(GLboolean flag) { mDepthMask = flag; } virtual void begin(GLenum mode) { flushState(); OpenGL::begin(mode); } ... private: void flushState() { OpenGL::depthMask(mDepthMask); ... } }; And so, my two questions: 1) As an end-user, if I was given this code (which is already built in a library or DLL that I cannot modify), is there any easy way for me to utilize the caching ability of the OpenGLCaching class, yet also allow logging through the provided OpenGLLogger class? My guess is "no", since I can't just derive from both classes -- the compiler won't know what virtual function to call in what order. 2) (Assuming #1 is no) As the developer, is there any design pattern I can use that would allow an end-user to be able to perform something like the above example? Perhaps some of the C++ gurus out there would have a better suggestion. Thanks!
  7. Try changing friend class U; to just friend U; in your ReadOnly class. I'm not sure how your class is being used, but the following code works fine for me: template<class T, class U> class ReadOnly { friend U; public: T Get(){return _privateValue;} private: void Private_Set(T value){_privateValue=value;} T _privateValue; }; class MyClass { public: template<class T, class U> void setReadOnly(ReadOnly<T, U> &ro, T value) { ro.Private_Set(value); } }; int main() { ReadOnly<int, MyClass> a; MyClass b; b.setReadOnly(a, 5); }
  8. Oh, I see what you mean -- that works even better as I can remove the other operator+ function. I didn't expect the compiler to automatically use the constructor in order to convert other types when applying the operator. I just recompiled with VS2005 and gcc, and it works fine. Thanks again!
  9. That seemed to do the trick. VS2005, gcc, and Comeau all compile without a problem after adding an explicit operator+ friend with MyClass<T> for both parameters. Thanks!
  10. So I thought it would be a great idea to add template friends to my class for the standard operators (add, subtract, etc.), so I could do cool things like a = 1 / b;, but I seem to have run into a bit of a problem. While gcc-4.4.0 accepts the following code just fine, both VS2005 and Comeau give an error about being ambiguous as to which operator to choose: template <typename T> class MyClass { public: MyClass() : mVal(0) { } MyClass(T val) : mVal(val) { } template <typename U> MyClass<T> operator +(U val) const { MyClass<T> res = *this; res.mVal += val; return res; } template <typename U> friend MyClass<T> operator +(U val, const MyClass<T> &myc) { return myc + val; } private: T mVal; }; int main() { MyClass<int> a, b, c; c = a + b; } Here's the actual error from Comeau (VS2005's error is pretty much the same): "ComeauTest.c", line 27: error: more than one operator "+" matches these operands: function template "MyClass<int> operator+(U, const MyClass<int> &)" function template "MyClass<int> MyClass<T>::operator+(U) const [with T=int]" operand types are: MyClass<int> + MyClass<int> c = a + b; ^ Any suggestions on what I might be doing wrong here, and how to possibly fix or work around this?
  11. Quote:Original post by Hodgman Can you make the vectors store pointers instead of actual elements, and then make the data class polymorphic? That's certainly one option -- but if possible, I would like the data structures to be linear in memory to avoid lots of small memory allocations and fragmentation. Although, an alternative extension to your idea would be to return a reference to a std::vector<> in the derived class, rather than just the individual structs themselves. The base class could contain it's own std::vector<> as well, but just not directly access it, using only the virtual call to get a reference to the desired container. Now that I think about it, this may not be such a bad solution. :)
  12. This code is from our sound engine. The SomeBigBaseClass is the base Device class, and the hardware-specific implementations (WaveOut, DirectSound, GBA, NDS, etc) derive from Device. There's also a software mixing layer that slides in as a derived Device itself, and devices which can't do hardware mixing derive from that software mixing Device. Each of the Data types are structures to channel info, sample data, or stream data. The base Device class has to implement quite a bit of functionality, and I was hoping I could get by without having to expose it all to the outside world just for the luxury of storing derived data structures internally. :) Any other suggestions, perhaps?
  13. I apologize for the weird subject line -- it was the best I could come up with. :) I've currently got a fairly large, base class which has three containers which hold data to other structures: struct DataA { int a; }; struct DataB { int b; }; struct DataC { float c; }; class SomeBigBaseClass { public: ...lots of public stuff... protected: virtual void doSomethingWithA(DataA *a) = 0; virtual void doSomethingWithB(DataB *b, int val) = 0; private: std::vector<DataA> mAList; std::vector<DataB> mBList; std::vector<DataC> mCList; }; Other classes derive from SomeBigBaseClass, and implement the virtual functions. I've been finding that depending on the derived classes' implementation, I need to "attach" extra data to some or all of the DataA, DataB, or DataC classes. Currently I make a separate struct, adding the extra variables I need, then use a lookup method to map the base DataA pointer to my separate version: struct MyDataA { int my_a; }; struct MyDataC { double my_c; }; class DerivedClass : public SomeBigBaseClass { protected: virtual void doSomethingWithA(DataA *a) { // map DataA pointer to MyDataA pointer, then use both DataA and MyDataA... } virtual void doSomethingWithB(DataB *b, int val) { } private: std::vector<MyDataA> mDataAList; std::vector<MyDataC> mDataCList; }; While this does work, it seems like there's a got to be a better (and cleaner) way to implement it. My first instinct was to make SomeBigBaseClass a template: template <class TA = DataA, class TB = DataB, class TC = DataC> class SomeBigBaseClass { public: ...lots of public stuff... protected: virtual void doSomethingWithA(DataA *a) = 0; virtual void doSomethingWithB(DataB *b, int val) = 0; private: std::vector<TA> mAList; std::vector<TB> mBList; std::vector<TC> mCList; }; This would allow me to derive from the base Data* objects, pass them to the construction of the base class, and the containers would then use the specified classes. The only problem I have with this is SomeBigBaseClass really is quite large, and by making it a template, I would need to shift all of the code out of the .cpp file and move it into the header -- not something I want to do. Do any of the gurus out there have any other suggestions or ideas on how this could be handled better? Thanks in advance!
  14. Quote:Original post by bubu LV Sorry, my mistake. It needs < operator, not == operator. Aaah, that was it -- I didn't have an operator < for MyVec. I added it and hash_map::find() always returns a proper result now. Sneftel, I hope you don't mind that I swiped your code. ;)
  15. I added some more debug info to my function, and now I'm absolutely sure hash_map::find() is not returning an iterator to the proper data on a collision: // check if returned index matches the data we are looking for const MyVec &vbufvec = mVtxBuf[iter->second]; if (vbufvec != vec) { LOG("hash map collision: {%.2f,%.2f,%.2f [%08Xh]} / {%.2f,%.2f,%.2f [%08Xh]}", vbufvec.x, vbufvec.y, vbufvec.z, (size_t)(vbufvec), vec.x, vec.y, vec.z, (size_t)(vec)); } This is what I'm getting from the logger: [MyIndexer::locateVertex]: hash map collision: {4784.40,0.00,-3639.60 [D9CFAF33h]} / {4720.20,0.00,-3102.60 [D9CFAF33h]} The vertex data is different, but the hash value for them is exactly the same -- this is definitely a collision. I'm using MSVC2005's implementation. Is there a bug here, perhaps?
  • Advertisement