Like Tree1Likes
  • 1 Post By manasij7479

Python to C++

This is a discussion on Python to C++ within the C++ Programming forums, part of the General Programming Boards category; Hello everyone ^^; long time no see lol. I sort of stop comming here because I stop learning c/c++ to ...

  1. #1
    adr
    adr is offline
    Registered User
    Join Date
    Dec 2005
    Posts
    155

    Python to C++

    Hello everyone ^^; long time no see lol. I sort of stop comming here because I stop learning c/c++ to learn python ^^; Well I am back sort of for some help in getting a c/c++ program hopfully going.

    There is one issue tho... I don't have any of the compliers and to be honest... if I can make it out without having to have one, that be great (yea... I am sort of asking you to program it and complie it for me =/)...

    I understand the rules, and I don't think I am breaking it when asking this, but can comeone help me covert the follow code from python to c/c++?

    Code:
    from math import sqrt, pow, floor
    
    
    class MatrixMap:
      def __init__(self):
        self.gridSize = 375
        self.GridMap = {}
    
    
      #------------------------------------------------------------------------------
      def Add_Area(self, Area):
        for x in Area:
          self.GridMap[x] = {}
    
    
      #------------------------------------------------------------------------------
      def Add(self, objects):
        for object in objects:
          self.SetIntoMap(object)
    
    
      #------------------------------------------------------------------------------
      def Update(self, objects):
        for object in objects:
          self.RemoveFromMap(object)
          self.SetIntoMap(object)
    
    
      #------------------------------------------------------------------------------
      def Remove(self, objects):
        for object in objects:
          self.RemoveFromMap(object)
    
    
      #------------------------------------------------------------------------------
      def BlockInfo(self, object, other="IP"):
        Block = []
        Poisition = object.Data("Position").split()
        for ZNum in xrange(-self.gridSize, self.gridSize+1, self.gridSize):
          Z = int((float(Poisition[2])+ZNum)/self.gridSize)
          for XNum in xrange(-self.gridSize, self.gridSize+1, self.gridSize):
            X = int((float(Poisition[0])+XNum)/self.gridSize)
            for YNum in xrange(-self.gridSize, self.gridSize+1, self.gridSize):
              Y = int((float(Poisition[1])+YNum)/self.gridSize)
              if (X,Y,Z) in self.GridMap[object.Data("Area")]:
                for objects in self.GridMap[object.Data("Area")][(X,Y,Z)]:
                  if objects not in Block and objects is not object and objects.Data("Type") in other:
                    Block.append(objects)
        return Block
    
    
      #------------------------------------------------------------------------------
      def CellInfo(self, object):
        Poisition = object.Data("Position").split()
        cell = int(float(Poisition[0])/self.gridSize), int(float(Poisition[1])/self.gridSize), int(float(Poisition[2])/self.gridSize)
        return self.GridMap[object.Data("Area")][cell]
    
    
      #------------------------------------------------------------------------------
      def SetIntoMap(self, object):
        Poisition = object.Data("Position").split()
        cell = int(float(Poisition[0])/self.gridSize), int(float(Poisition[1])/self.gridSize), int(float(Poisition[2])/self.gridSize)
        if cell in self.GridMap[object.Data("Area")]:
          if object not in self.GridMap[object.Data("Area")][cell]:
            self.GridMap[object.Data("Area")][cell].append(object)
        else:
          self.GridMap[object.Data("Area")][cell] = [object]
    
    
      #------------------------------------------------------------------------------
      def RemoveFromMap(self, object):
        DeleteList = []
        for Areas in self.GridMap:
          for Cells in self.GridMap[Areas]:
            if object in self.GridMap[Areas][Cells]:
              self.GridMap[Areas][Cells].remove(object)
    The idea is simple, but I am not sure how about passing python objects to c++ objects or is it all done auto-magic like?

    The code it self tracks objects in a 3d grid in blocks to help lower down the anount of update calls... aka Player A moves into block B... all objects in Block B gets the information about Player A movements now leaving all other blocks out of communation.
    Last edited by adr; 12-07-2011 at 01:19 PM.

  2. #2
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,498
    adr likes this.
    Manasij Mukherjee | gcc-4.8.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  3. #3
    adr
    adr is offline
    Registered User
    Join Date
    Dec 2005
    Posts
    155
    Thanks manasij ^^ I will take a look a it and update this thread as needed

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Python --> C
    By Macha in forum C Programming
    Replies: 71
    Last Post: 05-28-2010, 06:18 PM
  2. python c api
    By ralu. in forum C Programming
    Replies: 0
    Last Post: 03-01-2009, 12:19 PM
  3. C and Python
    By alexnb185 in forum Tech Board
    Replies: 5
    Last Post: 04-11-2008, 11:11 PM
  4. Python
    By mart_man00 in forum Tech Board
    Replies: 7
    Last Post: 10-06-2003, 07:24 AM
  5. anyone here knows Python ?
    By black in forum A Brief History of Cprogramming.com
    Replies: 17
    Last Post: 09-11-2002, 08:49 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21