Advertisement Jump to content
  • Advertisement

3Dgonewild

Member
  • Content Count

    314
  • Joined

  • Last visited

Community Reputation

174 Neutral

About 3Dgonewild

  • Rank
    Member
  1. Well you're right about profiling the code , but i was just asking for some more information on the subject , but it seems that no one actually did some research before. I haven't found a document that explains how a function is aligned. Eg: the variable members get aligned by N bytes ? If that's the case , then obviously on some platforms its possible to get interesting results(especially when dealing with large objects).
  2. Haven't asked stuff for a while , but here it goes :)... I've been doing a little research on gcc optimization options , and i've been wondering what exactly happens when i set a custom function align level. For example , if we had a cpu with 256kb cache divided into 32byte cache chunks(lines) , it would be efficient to set function align flag to 32 ? Also , are there any other cpu cache specific optimization flags that i should know? Thanks for your time :).
  3. Here's a simple example...hope it helps... class CSprite { public: CSprite(const CVector2& v,LPDIRECT3DTEXTURE9* texture_ref) :m_TextureRef(texture_ref){ m_Vec = v;} ~CSpite(){} const CVector2& getVector(); private: CVector2 m_Vec; LPDIRECT3DTEXTURE9* m_TextureRef; }; some list < LPDIRECT3DTEXTURE9 > textures; //load textures push texture to list some list < CSpire > sprites; ===some func to add sprites to the list=== void ??????::add(LPDIRECT3DTEXTURE9* tex_ref,CVector2& pos) { sprites push_back ( CSprite(pos,tex_ref) ); } //rendering void ??????::render(...) { for each sprite in list render its surface at getVector().x,y , with dimensions : getVector().w,h end }
  4. 3Dgonewild

    'when' keyword

    Long time ago i have had implemented a statement-behaviour system , that could do exactly that(but , its useless IMO-). Here's how the code looks like(on top of my head , don't bite :) ): struct StatementArg { StatementArg(){type=ST_UNKNOWN;cmp=false;} StatementArg(const int stype){type=stype;cmp=false;} StatementArg(const std::string& ss){s = ss; type = ST_STRING;cmp=false;} StatementArg(const int si){i = si; type = ST_INT;cmp=false;} StatementArg(const float sf){i = sf; type = ST_FLOAT;cmp=false;} unsigned int name; int type; union // or boost::any ?? { int i; float f; std::string s; } } struct StatementArgs { StatementArgs(){argc=0;} ~StatementArgs(){delete args;} unsigned int super; int argc; StatementArg* args; FuncPointer* func_ptr; FuncPointer* func_ptr_behaviour; bool cmp; }; void addToList(StatementArgs* arg , func_pointer,behaviour) { push (obj { arg&func_pointer&behaviour }) } Handling: StatementArgs* registerStatementArgs(Funcpointer* hook,FuncPointer* behaviour,const unsigned int top_level) { StatementArgs* ss = new StatementArgs; ss->super = top_level; addToList(arg,hook,behaviour); return ss; } void removeArgs(StatementArgs* args) { remove arg & sub arg fields } StatementArgs* getStatementArgs(const unsigned int top_level) { find func with arg name $$$top_level return statement } StatementArg* getStatementArgField(StatementArgs* super,const unsigned int name) { search for $name in args & return it; } void updateArgs() { for each arg for each sub field arg call arg->func_ptr & ->behaviour } Usage: class Instructions { .. }; class Comparison public Instructions { private: StatementArgs* args_ptr; public: void behaviour(StatementArg* arg) { args_ptr->cmp = (bool)( (args_ptr->args[0] + args_ptr->args[1]) == args_ptr->args[2]); } void onEq(StatementArg* arg) { std::cout<<"onEq called from hook manager"<<std::endl; std::cout<<"Arg->cmp : "<<arg->cmp<<std::endl; } Comparison() { args_ptr = registerStatementArgs(onEq,hashOf("onEq")); args_ptr->behaviour = behaviour; //register fields args_ptr->argc = 3; args_ptr->args = new StatementArg[args_ptr->argc]; args_ptr->args[0].name = hashOf("num1"); args_ptr->args[1].name = hashOf("num2"); args_ptr->args[2].name = hashOf("sum"); args_ptr->args[0].i = 0; args_ptr->args[1].i = 0; args_ptr->args[2].i = 0; args_ptr->args.type = ST_INT; } ~Comparison() { removeArgs(args_ptr); } } main() { Instruction* inst = new Instruction; inst = &Comparison; while running int a = 0 , b = 0 , ab = 0; get input a get input b get input ab getStatementArgField(getStatementArgs(hashOf("onEq")),hashOf("num2"))->i = a; getStatementArgField(getStatementArgs(hashOf("onEq")),hashOf("num1"))->i = b; getStatementArgField(getStatementArgs(hashOf("onEq")),hashOf("sum"))->i =ab; updateArgs } [Edited by - 3Dgonewild on January 21, 2009 4:18:38 AM]
  5. Thanks , that makes sense!... I think that i understand the concept of generating the tree , im just not sure how i should generate the final bytecode...hmm i'll try to find a way(i guess...)... Here's some "code" that i plan to use for the stream->tokenizer... struct TTokenType { TTokenType(){data=NULL; type = enums::TTypes::unknown_sym; prc_level = -9;} TTokenType(const TTokenType t,const ptr prc_lvl){type = t; prc_level = prc_lvl;data=NULL;} TTokenType(const TTokenType t,const ptr prc_lvl,const uiptr* &value){type = t; prc_level = prc_lvl;data=strdup(value);} enums::TTypes type; ptr prc_level; uiptr* data; }; struct TNodeElement { TNodeElement(){next=previous=child=NULL;} TTokenType token; TNodeElement* next; TNodeElement* previous; TNodeElement* child; }; TNodeElement* head , *tail ............ void tokenizeStream(const uiptr* &stream,const uptr stream_length,TNodeElement* tree); { tokenize each character and update the tree...: while in bounds skip white space if is alpha { token = getToken check to see if identifier exists if yes { v = get value(token) TTokenType tt(enums::value,0,v)); register token tt } otherwise rollback token }else{ switch **character case '(' : { TTokenType tt(enums::paren_open,-1)); register token tt } } void imaginaryHandleByteCodeFunction();...
  6. for I := 0 to Columns-1 do //modified for J := 0 to Rows-1 do //modified begin //also im not sure if the object must be allocated //since the declaration looks like it does the allocation... Inventory[J] := TInvBox.Create(DXSpriteEngine1.Engine);//swaped line //or maybe Inventory[J] := TInvBox.Create(self); ?? //or maybe Inventory[J] := TInvBox.Create(surface/form); ?? //if( Inventory[J] = nil )//also some debugging support //doDebug('unable to allocate image...'); Inventory[J].Column := I; Inventory[J].Row := J; Inventory[J].X := X + (Inventory[J].Row - 1)*Width; Inventory[J].Y := Y + (Inventory[J].Column - 1)*Height; Inventory[J].Z := 2; Inventory[J].Image := MainForm.TileMaps.Items[3]; //if( Inventory[J].Image = nil )//also some debugging support //doDebug('null image...'); end; end; ...
  7. Thanks for the replies!... Quote: I have no idea what you're asking. What i was asking for , is a way to parse complex expressions and generate the proper bytecode. For example , a simple expression like this one: uptr x = 128 * 2; ...can be handled easily , ... but what happens when we have complex expressions , like this one: uptr x = (128 * 2 - (88 + 12) / 2) * 2; Obviously the parser(in combination with compiler) must be smart in order to generate the proper bytecode , since it requires loads of stack related operations(when needed). Anyway , i think i found what i was asking for(thanks to phresnel), ...i have to implement an operator precedence function. Quote: If you are looking for fun and experience... Just for the experience of course :). Quote: In general, have a look at the freely available book Compiler Construction by Niklaus Wirth. Great! , looks really interesting!... Quote: Frontend / (Middleend /)? Backend. Frontend i guess :P...
  8. Hi everyone...how's it going?(im not expecting answers :P ). Well , anyway , ... First of all let me tell you that im working on a scripting language. I have nearly finished the virtual machine , and now im trying to create a parser(for the compiler) , and here comes the wave of questions : 1) What's the best approach of creating a parser for a compiler? Right now the parser work's like this: load code $given_source_file$ while reading stream skip white space std::string token = getDynamicToken(" \n\r");//stream to token buffer and return what we want do string comparison with token on "if" structure call parseIfStructure on "class" call parseClassStructure on "int" call parseIntIdentifier inc stream.head 2) What about expressions ? what's the most efficient way to handle them?. For example , how should i handle an expression like this one: (((b+128)*a) + (u * q %m) ); -> bytecode = //@compiler module set get_idf(b) push pop //vm->b is now $b set const 128 //vm->a is now 128 add // vm->a is now $b + 128 push get_idf(a) mul push set $u pop set $q mul push set mod 3) (bytecode related) Do i have to worry about endianess or no? 4) Any tips on how to organize such a project? That's all ..., Thanks for your time...
  9. 3Dgonewild

    c++ making a union inside a class

    How about this ? class V { private: float vector[3]; public: V(const float x,const float y,const float z){...v[0]=x etc} float& x(){return vector[0];} float& y(){return vector[1];} float& z(){return vector[2];} }; V v(50,32,50); v.x() = 125; print out v.x(); ( x =125)
  10. 3Dgonewild

    Pseudo code to bytecode converter ?

    Thanks all for the replies , -S flag is exactly what i've been looking for! Some quick tests : int i = 22; ->>>>>>>>>>>>>>> .file "main.cpp" .globl i .data .align 4 .type i, @object .size i, 4 i: .long 22 .ident "GCC: (Ubuntu 4.3.2-1ubuntu11) 4.3.2" .section .note.GNU-stack,"",@progbits void jmp_test() { bool jmp = false; if(jmp) { int something_to_test_jmp = 1; }else{ int something_to_test_jmp = 0; } } ->>>>>>>>>>>>>>> .file "main.cpp" .text .globl _Z8jmp_testv .type _Z8jmp_testv, @function _Z8jmp_testv: .LFB2: pushl %ebp .LCFI0: movl %esp, %ebp .LCFI1: subl $16, %esp .LCFI2: movb $0, -1(%ebp) cmpb $0, -1(%ebp) je .L2 movl $1, -8(%ebp) jmp .L4 .L2: movl $0, -12(%ebp) .L4: leave ret .LFE2: .size _Z8jmp_testv, .-_Z8jmp_testv .ident "GCC: (Ubuntu 4.3.2-1ubuntu11) 4.3.2" .section .note.GNU-stack,"",@progbits
  11. 3Dgonewild

    Set priority

    Quote:Original post by KontosHarry Cause I am making a program which needs to run at startup and it should not affect the CPU much... Well , why you don't just execute functions at fixed time ?? For example , in your (imaginary)"proccess()" function , add something similar to this: type application::proccess(arguments ?) { time_now = get_time_in_milliseconds dt = (time_now - last_time) last_time = time_now cycles += (uint)(1*(uint)dt) if(cycles >= 1000) { update stuff cycles = 0 } } It should work pretty well...
  12. Hi everyone , i'll try to be quick ... I'm looking for a tool (or something similar) that will convert some pseudo script code into bytecode so i can actually study a little bit better what's going on when , for example ,calling a function , or jumping outside of scope. For example , it should be able to turn this code: some_variable a = 1; into this (just an example): BC_PUSH addr BC_SET addr BC_POPA get from stack intptr(addr) ( a = 1 ) or something similar ... Any ideas if such a thing exists ???
  13. 3Dgonewild

    Image packaging methods

    An easy way to do it is the "half bit method". Here's some example code ( note: not complete of course , but you get an idea ). somePackPixelsFunction(const char** pixels,FILE** f,const int flags) { unsigned char* p = (unsigned char*)(*pixels); unsigned char r='\0',g='\0',b='\0'; char a='255'; //Step 1 : loop through the pixel buffer //set r g b r = *(p++); b = *(p++); g = *(p++); //Full bits if( flags & FULL_BITS) { //write each byte fwrite(&r, sizeof(unsigned char), sizeof(unsigned char), *f); fwrite(&g, sizeof(unsigned char), sizeof(unsigned char), *f); fwrite(&b, sizeof(unsigned char), sizeof(unsigned char), *f); fwrite(&a, sizeof(char), sizeof(char), *f); } else //HALF BITS... { unsigned short rgb_packed = (b >> 3)|((g >> 2) << 5)|((r >> 3) << 11); fwrite(&rgb_packed, sizeof(unsigned short), 1, *f); } } Hope it helps...
  14. 3Dgonewild

    2D zoom in Ortho mode

    Post the full source code , with source tags please. (source)(/source) (replace "(",")" with "[","]")
  15. 3Dgonewild

    2D zoom in Ortho mode

    Change this: glTranslatef(nx,ny,0.0f); //nx/ny: mouse lbuttondown x/y coord glScalef(scX,scY,1.0f); //scX,scY: factors inc/decreased at WM_MOUSEMOVE message glTranslatef(-nx,-ny,0.0f); for (i=0;i<4;i++){ glBegin(GL_LINES); // Grid horizontal glColor3f(0.5f,0.5f,0.5f); glVertex2d(0,i*50); glVertex2d(800,i*50); glEnd(); } for (i=0;i<16;i++){ //Grid vertical glBegin(GL_LINES); glColor3f(0.5f,0.5f,0.5f); glVertex2d(i*50,0); glVertex2d(i*50,200); glEnd(); To this(push/pop matrix hierarchy): //push camera glPushMatrix(); glScalef(scX,scY,1.0f); glTranslatef(nx,ny,0.0f); glScalef(1,1,0); for (i=0;i<4;i++) { glPushMatrix(); glBegin(GL_LINES); glColor3f(0.5f,0.5f,0.5f); glVertex2d(0,i*50); glVertex2d(800,i*50); glEnd(); glPopMatrix(); } for (i=0;i<16;i++) { glPushMatrix(); glBegin(GL_LINES); glColor3f(0.5f,0.5f,0.5f); glVertex2d(i*50,0); glVertex2d(i*50,200); glEnd(); glPopMatrix(); } //restore camera glPopMatrix();
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!